2003-01-05 08:05:17 +03:00
|
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2006-04-18 03:16:46 +04:00
|
|
|
|
/* vim: set ts=2 sw=2 et tw=78: */
|
2012-05-21 15:12:37 +04:00
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2003-01-05 08:05:17 +03:00
|
|
|
|
|
2013-08-14 10:56:21 +04:00
|
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
|
|
2013-12-09 06:52:54 +04:00
|
|
|
|
#include "mozilla/ArrayUtils.h"
|
2013-09-25 15:21:22 +04:00
|
|
|
|
#include "mozilla/BasicEvents.h"
|
2015-02-24 10:16:00 +03:00
|
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-10-19 14:47:22 +04:00
|
|
|
|
#include "mozilla/gfx/PathHelpers.h"
|
2014-11-15 03:45:23 +03:00
|
|
|
|
#include "mozilla/Likely.h"
|
2014-08-23 00:12:38 +04:00
|
|
|
|
#include "mozilla/Maybe.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
|
#include "mozilla/MemoryReporting.h"
|
2014-10-24 19:28:14 +04:00
|
|
|
|
#include "nsCharTraits.h"
|
2014-10-24 19:28:14 +04:00
|
|
|
|
#include "nsFontMetrics.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
|
#include "nsPresContext.h"
|
2003-01-05 08:05:17 +03:00
|
|
|
|
#include "nsIContent.h"
|
2010-04-21 17:13:08 +04:00
|
|
|
|
#include "nsIDOMHTMLDocument.h"
|
2010-04-25 23:52:23 +04:00
|
|
|
|
#include "nsIDOMHTMLElement.h"
|
2003-01-05 08:05:17 +03:00
|
|
|
|
#include "nsFrameList.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
|
#include "nsGkAtoms.h"
|
2015-02-11 00:28:07 +03:00
|
|
|
|
#include "nsHtml5Atoms.h"
|
2003-04-22 03:06:40 +04:00
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
|
#include "nsCSSPseudoElements.h"
|
2008-02-27 12:26:15 +03:00
|
|
|
|
#include "nsCSSAnonBoxes.h"
|
2011-06-22 22:11:48 +04:00
|
|
|
|
#include "nsCSSColorUtils.h"
|
2013-01-03 17:23:11 +04:00
|
|
|
|
#include "nsView.h"
|
2014-05-29 01:43:39 +04:00
|
|
|
|
#include "nsViewManager.h"
|
2004-09-13 17:35:46 +04:00
|
|
|
|
#include "nsPlaceholderFrame.h"
|
2004-09-21 08:41:08 +04:00
|
|
|
|
#include "nsIScrollableFrame.h"
|
2005-06-02 13:00:48 +04:00
|
|
|
|
#include "nsIDOMEvent.h"
|
2006-01-26 05:29:17 +03:00
|
|
|
|
#include "nsDisplayList.h"
|
|
|
|
|
#include "nsRegion.h"
|
2006-10-19 05:47:47 +04:00
|
|
|
|
#include "nsFrameManager.h"
|
2007-01-17 05:37:19 +03:00
|
|
|
|
#include "nsBlockFrame.h"
|
2007-01-23 05:58:55 +03:00
|
|
|
|
#include "nsBidiPresUtils.h"
|
2007-03-20 03:58:20 +03:00
|
|
|
|
#include "imgIContainer.h"
|
2013-08-29 02:39:07 +04:00
|
|
|
|
#include "ImageOps.h"
|
2014-08-23 00:12:38 +04:00
|
|
|
|
#include "ImageRegion.h"
|
2007-03-20 03:58:20 +03:00
|
|
|
|
#include "gfxRect.h"
|
2007-05-15 09:15:45 +04:00
|
|
|
|
#include "gfxContext.h"
|
2012-03-20 16:15:55 +04:00
|
|
|
|
#include "nsRenderingContext.h"
|
2007-03-20 03:58:20 +03:00
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2007-05-10 19:46:42 +04:00
|
|
|
|
#include "nsCSSRendering.h"
|
2008-08-13 04:44:14 +04:00
|
|
|
|
#include "nsThemeConstants.h"
|
2008-07-26 20:14:49 +04:00
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
|
#include "nsIWidget.h"
|
2008-09-13 13:42:11 +04:00
|
|
|
|
#include "gfxMatrix.h"
|
2014-04-04 18:13:30 +04:00
|
|
|
|
#include "gfxPrefs.h"
|
2008-09-13 13:42:11 +04:00
|
|
|
|
#include "gfxTypes.h"
|
2009-02-03 17:42:18 +03:00
|
|
|
|
#include "nsTArray.h"
|
2013-01-04 09:16:14 +04:00
|
|
|
|
#include "mozilla/dom/HTMLCanvasElement.h"
|
2009-06-26 00:30:56 +04:00
|
|
|
|
#include "nsICanvasRenderingContextInternal.h"
|
|
|
|
|
#include "gfxPlatform.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
|
#include <algorithm>
|
2014-12-04 08:21:42 +03:00
|
|
|
|
#include <limits>
|
2013-03-19 16:27:35 +04:00
|
|
|
|
#include "mozilla/dom/HTMLVideoElement.h"
|
2012-12-31 21:25:46 +04:00
|
|
|
|
#include "mozilla/dom/HTMLImageElement.h"
|
2013-09-20 14:21:03 +04:00
|
|
|
|
#include "mozilla/dom/DOMRect.h"
|
2015-04-15 02:48:21 +03:00
|
|
|
|
#include "mozilla/dom/KeyframeEffect.h"
|
2009-06-26 00:30:56 +04:00
|
|
|
|
#include "imgIRequest.h"
|
|
|
|
|
#include "nsIImageLoadingContent.h"
|
2009-09-01 20:40:49 +04:00
|
|
|
|
#include "nsCOMPtr.h"
|
2012-10-03 09:04:50 +04:00
|
|
|
|
#include "nsCSSProps.h"
|
2010-01-12 00:45:18 +03:00
|
|
|
|
#include "nsListControlFrame.h"
|
2010-05-05 22:18:05 +04:00
|
|
|
|
#include "mozilla/dom/Element.h"
|
2010-07-16 01:07:52 +04:00
|
|
|
|
#include "nsCanvasFrame.h"
|
2010-08-13 17:30:37 +04:00
|
|
|
|
#include "gfxDrawable.h"
|
|
|
|
|
#include "gfxUtils.h"
|
2011-01-13 20:45:14 +03:00
|
|
|
|
#include "nsDataHashtable.h"
|
2011-06-16 10:31:36 +04:00
|
|
|
|
#include "nsTextFrame.h"
|
|
|
|
|
#include "nsFontFaceList.h"
|
2012-04-17 02:32:12 +04:00
|
|
|
|
#include "nsFontInflationData.h"
|
2008-02-27 12:26:15 +03:00
|
|
|
|
#include "nsSVGUtils.h"
|
2014-08-23 00:12:38 +04:00
|
|
|
|
#include "SVGImageContext.h"
|
2013-12-20 20:38:51 +04:00
|
|
|
|
#include "SVGTextFrame.h"
|
2012-08-08 15:37:13 +04:00
|
|
|
|
#include "nsStyleStructInlines.h"
|
2013-03-03 04:31:48 +04:00
|
|
|
|
#include "nsStyleTransformMatrix.h"
|
2013-10-02 01:00:38 +04:00
|
|
|
|
#include "nsIFrameInlines.h"
|
2013-10-02 04:57:50 +04:00
|
|
|
|
#include "ImageContainer.h"
|
2013-10-03 14:58:01 +04:00
|
|
|
|
#include "nsComputedDOMStyle.h"
|
2013-09-10 04:08:41 +04:00
|
|
|
|
#include "ActiveLayerTracker.h"
|
2013-12-12 01:05:27 +04:00
|
|
|
|
#include "mozilla/gfx/2D.h"
|
2013-12-13 21:32:02 +04:00
|
|
|
|
#include "gfx2DGlue.h"
|
2014-03-27 05:46:23 +04:00
|
|
|
|
#include "mozilla/LookAndFeel.h"
|
2014-04-04 18:13:09 +04:00
|
|
|
|
#include "UnitTransforms.h"
|
2014-03-19 21:29:24 +04:00
|
|
|
|
#include "TiledLayerBuffer.h" // For TILEDLAYERBUFFER_TILE_SIZE
|
2014-04-22 03:48:54 +04:00
|
|
|
|
#include "ClientLayerManager.h"
|
2014-05-29 01:43:39 +04:00
|
|
|
|
#include "nsRefreshDriver.h"
|
2014-07-29 22:50:48 +04:00
|
|
|
|
#include "nsIContentViewer.h"
|
2014-08-02 14:03:00 +04:00
|
|
|
|
#include "LayersLogging.h"
|
2011-08-03 07:04:19 +04:00
|
|
|
|
#include "mozilla/Preferences.h"
|
2014-08-06 09:19:27 +04:00
|
|
|
|
#include "nsFrameSelection.h"
|
|
|
|
|
#include "FrameLayerBuilder.h"
|
2014-10-16 17:23:52 +04:00
|
|
|
|
#include "mozilla/layers/APZCTreeManager.h"
|
2014-12-08 23:43:16 +03:00
|
|
|
|
#include "mozilla/Telemetry.h"
|
2015-02-25 06:20:00 +03:00
|
|
|
|
#include "mozilla/EventDispatcher.h"
|
2015-04-21 06:48:10 +03:00
|
|
|
|
#include "mozilla/EventStateManager.h"
|
2015-06-23 04:48:18 +03:00
|
|
|
|
#include "mozilla/RuleNodeCacheConditions.h"
|
2011-08-03 07:04:19 +04:00
|
|
|
|
|
2010-03-19 08:02:53 +03:00
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
|
#include "nsXULPopupManager.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-03-18 18:25:50 +04:00
|
|
|
|
#include "GeckoProfiler.h"
|
2012-07-31 21:28:22 +04:00
|
|
|
|
#include "nsAnimationManager.h"
|
|
|
|
|
#include "nsTransitionManager.h"
|
2013-08-20 02:55:18 +04:00
|
|
|
|
#include "RestyleManager.h"
|
2014-03-19 21:29:24 +04:00
|
|
|
|
|
2011-10-11 09:50:08 +04:00
|
|
|
|
using namespace mozilla;
|
2010-04-30 17:12:05 +04:00
|
|
|
|
using namespace mozilla::dom;
|
2014-08-23 00:12:38 +04:00
|
|
|
|
using namespace mozilla::image;
|
2012-12-12 01:12:43 +04:00
|
|
|
|
using namespace mozilla::layers;
|
2012-01-25 05:21:29 +04:00
|
|
|
|
using namespace mozilla::layout;
|
2013-12-12 01:05:27 +04:00
|
|
|
|
using namespace mozilla::gfx;
|
2010-03-02 02:41:49 +03:00
|
|
|
|
|
2014-02-27 11:45:29 +04:00
|
|
|
|
#define GRID_ENABLED_PREF_NAME "layout.css.grid.enabled"
|
2014-07-23 06:08:01 +04:00
|
|
|
|
#define RUBY_ENABLED_PREF_NAME "layout.css.ruby.enabled"
|
2013-09-06 02:47:08 +04:00
|
|
|
|
#define STICKY_ENABLED_PREF_NAME "layout.css.sticky.enabled"
|
2014-11-20 21:24:09 +03:00
|
|
|
|
#define DISPLAY_CONTENTS_ENABLED_PREF_NAME "layout.css.display-contents.enabled"
|
2013-10-28 00:56:32 +04:00
|
|
|
|
#define TEXT_ALIGN_TRUE_ENABLED_PREF_NAME "layout.css.text-align-true-value.enabled"
|
2012-10-03 09:04:50 +04:00
|
|
|
|
|
2010-10-13 14:52:45 +04:00
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
// TODO: remove, see bug 598468.
|
|
|
|
|
bool nsLayoutUtils::gPreventAssertInCompareTreePosition = false;
|
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
2011-01-13 20:45:14 +03:00
|
|
|
|
typedef FrameMetrics::ViewID ViewID;
|
2015-04-28 21:55:42 +03:00
|
|
|
|
typedef nsStyleTransformMatrix::TransformReferenceBox TransformReferenceBox;
|
2010-10-12 00:07:59 +04:00
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
/* static */ uint32_t nsLayoutUtils::sFontSizeInflationEmPerLine;
|
|
|
|
|
/* static */ uint32_t nsLayoutUtils::sFontSizeInflationMinTwips;
|
|
|
|
|
/* static */ uint32_t nsLayoutUtils::sFontSizeInflationLineThreshold;
|
2012-10-15 23:03:37 +04:00
|
|
|
|
/* static */ int32_t nsLayoutUtils::sFontSizeInflationMappingIntercept;
|
|
|
|
|
/* static */ uint32_t nsLayoutUtils::sFontSizeInflationMaxRatio;
|
2012-11-20 23:55:14 +04:00
|
|
|
|
/* static */ bool nsLayoutUtils::sFontSizeInflationForceEnabled;
|
2012-11-29 00:16:01 +04:00
|
|
|
|
/* static */ bool nsLayoutUtils::sFontSizeInflationDisabledInMasterProcess;
|
2013-05-14 03:47:02 +04:00
|
|
|
|
/* static */ bool nsLayoutUtils::sInvalidationDebuggingIsEnabled;
|
2013-12-12 06:09:40 +04:00
|
|
|
|
/* static */ bool nsLayoutUtils::sCSSVariablesEnabled;
|
2014-04-10 08:47:58 +04:00
|
|
|
|
/* static */ bool nsLayoutUtils::sInterruptibleReflowEnabled;
|
2015-05-25 00:40:37 +03:00
|
|
|
|
/* static */ bool nsLayoutUtils::sSVGTransformOriginEnabled;
|
2011-11-24 06:48:23 +04:00
|
|
|
|
|
2011-01-13 20:45:14 +03:00
|
|
|
|
static ViewID sScrollIdCounter = FrameMetrics::START_SCROLL_ID;
|
|
|
|
|
|
|
|
|
|
typedef nsDataHashtable<nsUint64HashKey, nsIContent*> ContentMap;
|
2012-10-03 04:18:48 +04:00
|
|
|
|
static ContentMap* sContentMap = nullptr;
|
2011-01-13 20:45:14 +03:00
|
|
|
|
static ContentMap& GetContentMap() {
|
|
|
|
|
if (!sContentMap) {
|
|
|
|
|
sContentMap = new ContentMap();
|
|
|
|
|
}
|
|
|
|
|
return *sContentMap;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 11:45:29 +04:00
|
|
|
|
// When the pref "layout.css.grid.enabled" changes, this function is invoked
|
|
|
|
|
// to let us update kDisplayKTable, to selectively disable or restore the
|
|
|
|
|
// entries for "grid" and "inline-grid" in that table.
|
|
|
|
|
static void
|
|
|
|
|
GridEnabledPrefChangeCallback(const char* aPrefName, void* aClosure)
|
|
|
|
|
{
|
|
|
|
|
MOZ_ASSERT(strncmp(aPrefName, GRID_ENABLED_PREF_NAME,
|
|
|
|
|
ArrayLength(GRID_ENABLED_PREF_NAME)) == 0,
|
|
|
|
|
"We only registered this callback for a single pref, so it "
|
|
|
|
|
"should only be called for that pref");
|
|
|
|
|
|
|
|
|
|
static int32_t sIndexOfGridInDisplayTable;
|
|
|
|
|
static int32_t sIndexOfInlineGridInDisplayTable;
|
|
|
|
|
static bool sAreGridKeywordIndicesInitialized; // initialized to false
|
|
|
|
|
|
|
|
|
|
bool isGridEnabled =
|
|
|
|
|
Preferences::GetBool(GRID_ENABLED_PREF_NAME, false);
|
|
|
|
|
if (!sAreGridKeywordIndicesInitialized) {
|
|
|
|
|
// First run: find the position of "grid" and "inline-grid" in
|
|
|
|
|
// kDisplayKTable.
|
|
|
|
|
sIndexOfGridInDisplayTable =
|
|
|
|
|
nsCSSProps::FindIndexOfKeyword(eCSSKeyword_grid,
|
|
|
|
|
nsCSSProps::kDisplayKTable);
|
|
|
|
|
MOZ_ASSERT(sIndexOfGridInDisplayTable >= 0,
|
|
|
|
|
"Couldn't find grid in kDisplayKTable");
|
|
|
|
|
sIndexOfInlineGridInDisplayTable =
|
|
|
|
|
nsCSSProps::FindIndexOfKeyword(eCSSKeyword_inline_grid,
|
|
|
|
|
nsCSSProps::kDisplayKTable);
|
|
|
|
|
MOZ_ASSERT(sIndexOfInlineGridInDisplayTable >= 0,
|
|
|
|
|
"Couldn't find inline-grid in kDisplayKTable");
|
|
|
|
|
sAreGridKeywordIndicesInitialized = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OK -- now, stomp on or restore the "grid" entries in kDisplayKTable,
|
|
|
|
|
// depending on whether the grid pref is enabled vs. disabled.
|
|
|
|
|
if (sIndexOfGridInDisplayTable >= 0) {
|
|
|
|
|
nsCSSProps::kDisplayKTable[sIndexOfGridInDisplayTable] =
|
|
|
|
|
isGridEnabled ? eCSSKeyword_grid : eCSSKeyword_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
if (sIndexOfInlineGridInDisplayTable >= 0) {
|
|
|
|
|
nsCSSProps::kDisplayKTable[sIndexOfInlineGridInDisplayTable] =
|
|
|
|
|
isGridEnabled ? eCSSKeyword_inline_grid : eCSSKeyword_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-23 06:08:01 +04:00
|
|
|
|
static void
|
|
|
|
|
RubyEnabledPrefChangeCallback(const char* aPrefName, void* aClosure)
|
|
|
|
|
{
|
|
|
|
|
MOZ_ASSERT(strncmp(aPrefName, RUBY_ENABLED_PREF_NAME,
|
|
|
|
|
ArrayLength(RUBY_ENABLED_PREF_NAME)) == 0,
|
|
|
|
|
"We only registered this callback for a single pref, so it "
|
|
|
|
|
"should only be called for that pref");
|
|
|
|
|
|
|
|
|
|
static int32_t sIndexOfRubyInDisplayTable;
|
|
|
|
|
static int32_t sIndexOfRubyBaseInDisplayTable;
|
|
|
|
|
static int32_t sIndexOfRubyBaseContainerInDisplayTable;
|
|
|
|
|
static int32_t sIndexOfRubyTextInDisplayTable;
|
|
|
|
|
static int32_t sIndexOfRubyTextContainerInDisplayTable;
|
|
|
|
|
static bool sAreRubyKeywordIndicesInitialized; // initialized to false
|
|
|
|
|
|
|
|
|
|
bool isRubyEnabled =
|
|
|
|
|
Preferences::GetBool(RUBY_ENABLED_PREF_NAME, false);
|
|
|
|
|
if (!sAreRubyKeywordIndicesInitialized) {
|
|
|
|
|
// First run: find the position of the ruby display values in
|
|
|
|
|
// kDisplayKTable.
|
|
|
|
|
sIndexOfRubyInDisplayTable =
|
|
|
|
|
nsCSSProps::FindIndexOfKeyword(eCSSKeyword_ruby,
|
|
|
|
|
nsCSSProps::kDisplayKTable);
|
|
|
|
|
MOZ_ASSERT(sIndexOfRubyInDisplayTable >= 0,
|
|
|
|
|
"Couldn't find ruby in kDisplayKTable");
|
|
|
|
|
sIndexOfRubyBaseInDisplayTable =
|
|
|
|
|
nsCSSProps::FindIndexOfKeyword(eCSSKeyword_ruby_base,
|
|
|
|
|
nsCSSProps::kDisplayKTable);
|
|
|
|
|
MOZ_ASSERT(sIndexOfRubyBaseInDisplayTable >= 0,
|
|
|
|
|
"Couldn't find ruby-base in kDisplayKTable");
|
|
|
|
|
sIndexOfRubyBaseContainerInDisplayTable =
|
|
|
|
|
nsCSSProps::FindIndexOfKeyword(eCSSKeyword_ruby_base_container,
|
|
|
|
|
nsCSSProps::kDisplayKTable);
|
|
|
|
|
MOZ_ASSERT(sIndexOfRubyBaseContainerInDisplayTable >= 0,
|
|
|
|
|
"Couldn't find ruby-base-container in kDisplayKTable");
|
|
|
|
|
sIndexOfRubyTextInDisplayTable =
|
|
|
|
|
nsCSSProps::FindIndexOfKeyword(eCSSKeyword_ruby_text,
|
|
|
|
|
nsCSSProps::kDisplayKTable);
|
|
|
|
|
MOZ_ASSERT(sIndexOfRubyTextInDisplayTable >= 0,
|
|
|
|
|
"Couldn't find ruby-text in kDisplayKTable");
|
|
|
|
|
sIndexOfRubyTextContainerInDisplayTable =
|
|
|
|
|
nsCSSProps::FindIndexOfKeyword(eCSSKeyword_ruby_text_container,
|
|
|
|
|
nsCSSProps::kDisplayKTable);
|
|
|
|
|
MOZ_ASSERT(sIndexOfRubyTextContainerInDisplayTable >= 0,
|
|
|
|
|
"Couldn't find ruby-text-container in kDisplayKTable");
|
|
|
|
|
sAreRubyKeywordIndicesInitialized = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OK -- now, stomp on or restore the "ruby" entries in kDisplayKTable,
|
|
|
|
|
// depending on whether the ruby pref is enabled vs. disabled.
|
|
|
|
|
if (sIndexOfRubyInDisplayTable >= 0) {
|
|
|
|
|
nsCSSProps::kDisplayKTable[sIndexOfRubyInDisplayTable] =
|
|
|
|
|
isRubyEnabled ? eCSSKeyword_ruby : eCSSKeyword_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
if (sIndexOfRubyBaseInDisplayTable >= 0) {
|
|
|
|
|
nsCSSProps::kDisplayKTable[sIndexOfRubyBaseInDisplayTable] =
|
|
|
|
|
isRubyEnabled ? eCSSKeyword_ruby_base : eCSSKeyword_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
if (sIndexOfRubyBaseContainerInDisplayTable >= 0) {
|
|
|
|
|
nsCSSProps::kDisplayKTable[sIndexOfRubyBaseContainerInDisplayTable] =
|
|
|
|
|
isRubyEnabled ? eCSSKeyword_ruby_base_container : eCSSKeyword_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
if (sIndexOfRubyTextInDisplayTable >= 0) {
|
|
|
|
|
nsCSSProps::kDisplayKTable[sIndexOfRubyTextInDisplayTable] =
|
|
|
|
|
isRubyEnabled ? eCSSKeyword_ruby_text : eCSSKeyword_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
if (sIndexOfRubyTextContainerInDisplayTable >= 0) {
|
|
|
|
|
nsCSSProps::kDisplayKTable[sIndexOfRubyTextContainerInDisplayTable] =
|
|
|
|
|
isRubyEnabled ? eCSSKeyword_ruby_text_container : eCSSKeyword_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-06 02:47:08 +04:00
|
|
|
|
// When the pref "layout.css.sticky.enabled" changes, this function is invoked
|
|
|
|
|
// to let us update kPositionKTable, to selectively disable or restore the
|
|
|
|
|
// entry for "sticky" in that table.
|
2013-12-11 03:10:01 +04:00
|
|
|
|
static void
|
2013-09-06 02:47:08 +04:00
|
|
|
|
StickyEnabledPrefChangeCallback(const char* aPrefName, void* aClosure)
|
|
|
|
|
{
|
|
|
|
|
MOZ_ASSERT(strncmp(aPrefName, STICKY_ENABLED_PREF_NAME,
|
2014-01-30 22:26:54 +04:00
|
|
|
|
ArrayLength(STICKY_ENABLED_PREF_NAME)) == 0,
|
2013-09-06 02:47:08 +04:00
|
|
|
|
"We only registered this callback for a single pref, so it "
|
|
|
|
|
"should only be called for that pref");
|
|
|
|
|
|
2013-09-19 06:19:23 +04:00
|
|
|
|
static int32_t sIndexOfStickyInPositionTable;
|
|
|
|
|
static bool sIsStickyKeywordIndexInitialized; // initialized to false
|
|
|
|
|
|
2013-09-06 02:47:08 +04:00
|
|
|
|
bool isStickyEnabled =
|
|
|
|
|
Preferences::GetBool(STICKY_ENABLED_PREF_NAME, false);
|
|
|
|
|
|
|
|
|
|
if (!sIsStickyKeywordIndexInitialized) {
|
|
|
|
|
// First run: find the position of "sticky" in kPositionKTable.
|
|
|
|
|
sIndexOfStickyInPositionTable =
|
|
|
|
|
nsCSSProps::FindIndexOfKeyword(eCSSKeyword_sticky,
|
|
|
|
|
nsCSSProps::kPositionKTable);
|
|
|
|
|
MOZ_ASSERT(sIndexOfStickyInPositionTable >= 0,
|
|
|
|
|
"Couldn't find sticky in kPositionKTable");
|
|
|
|
|
sIsStickyKeywordIndexInitialized = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OK -- now, stomp on or restore the "sticky" entry in kPositionKTable,
|
|
|
|
|
// depending on whether the sticky pref is enabled vs. disabled.
|
|
|
|
|
nsCSSProps::kPositionKTable[sIndexOfStickyInPositionTable] =
|
|
|
|
|
isStickyEnabled ? eCSSKeyword_sticky : eCSSKeyword_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-20 21:24:09 +03:00
|
|
|
|
// When the pref "layout.css.display-contents.enabled" changes, this function is
|
|
|
|
|
// invoked to let us update kDisplayKTable, to selectively disable or restore
|
|
|
|
|
// the entries for "contents" in that table.
|
|
|
|
|
static void
|
|
|
|
|
DisplayContentsEnabledPrefChangeCallback(const char* aPrefName, void* aClosure)
|
|
|
|
|
{
|
|
|
|
|
NS_ASSERTION(strcmp(aPrefName, DISPLAY_CONTENTS_ENABLED_PREF_NAME) == 0,
|
|
|
|
|
"Did you misspell " DISPLAY_CONTENTS_ENABLED_PREF_NAME " ?");
|
|
|
|
|
|
|
|
|
|
static bool sIsDisplayContentsKeywordIndexInitialized;
|
|
|
|
|
static int32_t sIndexOfContentsInDisplayTable;
|
|
|
|
|
bool isDisplayContentsEnabled =
|
|
|
|
|
Preferences::GetBool(DISPLAY_CONTENTS_ENABLED_PREF_NAME, false);
|
|
|
|
|
|
|
|
|
|
if (!sIsDisplayContentsKeywordIndexInitialized) {
|
|
|
|
|
// First run: find the position of "contents" in kDisplayKTable.
|
|
|
|
|
sIndexOfContentsInDisplayTable =
|
|
|
|
|
nsCSSProps::FindIndexOfKeyword(eCSSKeyword_contents,
|
|
|
|
|
nsCSSProps::kDisplayKTable);
|
|
|
|
|
sIsDisplayContentsKeywordIndexInitialized = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OK -- now, stomp on or restore the "contents" entry in kDisplayKTable,
|
|
|
|
|
// depending on whether the pref is enabled vs. disabled.
|
|
|
|
|
if (sIndexOfContentsInDisplayTable >= 0) {
|
|
|
|
|
nsCSSProps::kDisplayKTable[sIndexOfContentsInDisplayTable] =
|
|
|
|
|
isDisplayContentsEnabled ? eCSSKeyword_contents : eCSSKeyword_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-28 00:56:32 +04:00
|
|
|
|
// When the pref "layout.css.text-align-true-value.enabled" changes, this
|
|
|
|
|
// function is called to let us update kTextAlignKTable & kTextAlignLastKTable,
|
|
|
|
|
// to selectively disable or restore the entries for "true" in those tables.
|
2013-12-11 03:10:01 +04:00
|
|
|
|
static void
|
2013-10-28 00:56:32 +04:00
|
|
|
|
TextAlignTrueEnabledPrefChangeCallback(const char* aPrefName, void* aClosure)
|
|
|
|
|
{
|
|
|
|
|
NS_ASSERTION(strcmp(aPrefName, TEXT_ALIGN_TRUE_ENABLED_PREF_NAME) == 0,
|
|
|
|
|
"Did you misspell " TEXT_ALIGN_TRUE_ENABLED_PREF_NAME " ?");
|
|
|
|
|
|
|
|
|
|
static bool sIsInitialized;
|
|
|
|
|
static int32_t sIndexOfTrueInTextAlignTable;
|
|
|
|
|
static int32_t sIndexOfTrueInTextAlignLastTable;
|
|
|
|
|
bool isTextAlignTrueEnabled =
|
|
|
|
|
Preferences::GetBool(TEXT_ALIGN_TRUE_ENABLED_PREF_NAME, false);
|
|
|
|
|
|
|
|
|
|
if (!sIsInitialized) {
|
|
|
|
|
// First run: find the position of "true" in kTextAlignKTable.
|
|
|
|
|
sIndexOfTrueInTextAlignTable =
|
|
|
|
|
nsCSSProps::FindIndexOfKeyword(eCSSKeyword_true,
|
|
|
|
|
nsCSSProps::kTextAlignKTable);
|
|
|
|
|
// First run: find the position of "true" in kTextAlignLastKTable.
|
|
|
|
|
sIndexOfTrueInTextAlignLastTable =
|
|
|
|
|
nsCSSProps::FindIndexOfKeyword(eCSSKeyword_true,
|
|
|
|
|
nsCSSProps::kTextAlignLastKTable);
|
|
|
|
|
sIsInitialized = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OK -- now, stomp on or restore the "true" entry in the keyword tables,
|
|
|
|
|
// depending on whether the pref is enabled vs. disabled.
|
|
|
|
|
MOZ_ASSERT(sIndexOfTrueInTextAlignTable >= 0);
|
|
|
|
|
nsCSSProps::kTextAlignKTable[sIndexOfTrueInTextAlignTable] =
|
|
|
|
|
isTextAlignTrueEnabled ? eCSSKeyword_true : eCSSKeyword_UNKNOWN;
|
|
|
|
|
MOZ_ASSERT(sIndexOfTrueInTextAlignLastTable >= 0);
|
|
|
|
|
nsCSSProps::kTextAlignLastKTable[sIndexOfTrueInTextAlignLastTable] =
|
|
|
|
|
isTextAlignTrueEnabled ? eCSSKeyword_true : eCSSKeyword_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 15:30:57 +04:00
|
|
|
|
bool
|
2015-07-01 18:55:51 +03:00
|
|
|
|
nsLayoutUtils::HasAnimationsForCompositor(const nsIFrame* aFrame,
|
|
|
|
|
nsCSSProperty aProperty)
|
|
|
|
|
{
|
|
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
|
|
|
|
return presContext->AnimationManager()->GetAnimationsForCompositor(aFrame, aProperty) ||
|
|
|
|
|
presContext->TransitionManager()->GetAnimationsForCompositor(aFrame, aProperty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
Bug 1181392 part 5 - Remove use of IsFinishedTransition from AnimationCollection::HasAnimationOfProperty; r=dbaron
AnimationCollection::HasAnimationOfProperty uses IsFinishedTransition to filter
out transitions that should otherwise be ignored. This is used in the following
places:
1. nsLayoutUtils::HasAnimations
The is only used by nsIFrame::BuildDisplayListForStackingContext to see if
there are any opacity animations
For this case, simply returning *current* animations would be sufficient
(since finished but filling animations should have already filled in the
display opacity)
2. CommonAnimationManager::GetAnimationsForCompositor
This should really only return *current* animations--that is, animations that
are running or scheduled to run. Finished animations never run on the
compositor. Indeed, only *playing* animations run on the compositor but, as
we will see in some of the cases below, it is sometimes useful to know that
an animation *will* run on the compositor in the near future (e.g. so we can
pre-render content).
The places where GetAnimationsForCompositor is used are:
- When building layers to add animations to layers in nsDisplayList--in this
case we skip any animations that aren't playing so if
GetAnimationsForCompositor only returned current animations that would be
more than sufficient.
- In nsLayoutUtils::HasAnimationsForCompositor. This in turn is used:
- In ChooseScaleAndSetTransform to see if the transform is being animated
on the compositor. If so, it calls
nsLayoutUtils::ComputeSuitableScaleForAnimation (which also calls
GetAnimationsForCompositor) and passes the result to
GetMinAndMaxScaleForAnimationProperty which we have already adjusted in
part 4 of this patch series to only deal with *relevant* animations
Relevant animations include both current animations and in effect
animations but we don't run forwards-filling animations on the compositor
so GetAnimationsForCompositor should NOT return them. Current animations
should be enough. In fact, playing animations should be enough but we
might want to pre-render layers at a suitable size during their delay
phase so returning current animations is probably ok.
- In nsDisplayListBuilder::MarkOutOfFlowFrameForDisplay to add a fuzz
factor to the overflow rect for frames undergoing a transform animation
on the compositor. In this case too current animations should be
sufficient.
- In nsDisplayOpacity::NeedsActiveLayer to say "yes" if we are animating
opacity on the compositor. Presumably in this case it would be good to
say "yes" if the animation is in the delay phase too (as it currently
does). After the animation is finished, we should drop the layer, i.e.
current animations should be sufficient.
- In nsDisplayTransform::ShouldPrerenderTransformedContent. As with
nsDisplayOpacity::NeedsActiveLayer, we only need to pre-render
transformed content for animations that are current.
- In nsDisplayTransform::GetLayerState. As with
nsDisplayOpacity::NeedsActiveLayer, we only need to return active here
for current animations.
- In nsIFrame::IsTransformed. Here we test the display style to see if
there is a transform and also check if transform is being animated on the
compositor. As a result, we really only need HasAnimationsForCompositor
to return true for animations that are playing--otherwise the display
style will tell us if we're transformed or not. Returning true for all
current compositor animations (which is a superset of playing), however,
should not cause problems (we already return true for even more than
that).
- In nsIFrame::HasOpacityInternal which is much the same as
nsIFrame::IsTransformed and hence current should be fine.
3. AnimationCollection::CanThrottleAnimation
Here, HasAnimationOfProperty is used when looking for animations that would
disqualify us from throttling the animation by having an out-of-date layer
generation or being a transform animation that affects scroll and so requires
that we do the occasional main thread sample to update scrollbars.
It would seem like current animations are enough here too. One interesting
case is where we *had* a compositor animation but it has finished or been
cancelled. In that case, the animation won't be current and we should not
throttle the animation since we need to take it off its layer.
It turns out checking for current animations is still ok in this case too.
The reasoning is as follows:
- If the animation is newly-finished, we'll pick that up in
Animation::CanThrottle and return false then.
- If the animation is newly-idle then there are two cases:
If the cancelled animation was the only compositor animation then
AnimationCollection::CanPerformOnCompositorThread will notice that there
are no playing compositor animations and return false and
AnimationCollection::CanThrottleAnimation will never be called.
If there are other compositor animations running, then
AnimationCollection::CanThrottleAnimation will still return false because
whatever cancelled the animation will update the animation generation and
we'll notice the mismatch between the layer animation generation and the
animation generation on the collection.
Based on the above analysis it appears that making
AnimationCollection::HasAnimationOfProperty return only current animations (and
simulatneously renaming it to HasCurrentAnimationOfProperty) is safe. Indeed, in
effect, we already do this for transitions but not for animations. This patch
generalizes this behavior to all animations.
This patch also updates test_animations_omta.html since it was incorrectly
testing that a finished opacity animation was still running on the compositor.
Finished animations should not run on the compositor and the changes in this
patch cause that to happen. The reason we don't just update this test to check
for RunningOn.MainThread is that for opacity animations, unlike transform
animations, we can't detect if an opacity on a layer was set by animation or
not. As a result, for opacity animations we typically test the opacity on
either the main thread or compositor in order to allow for the case where an
animation-set opacity is still lingering on the compositor.
2015-08-07 06:29:36 +03:00
|
|
|
|
nsLayoutUtils::HasCurrentAnimationOfProperty(const nsIFrame* aFrame,
|
|
|
|
|
nsCSSProperty aProperty)
|
2013-09-04 15:30:57 +04:00
|
|
|
|
{
|
2015-07-01 21:43:13 +03:00
|
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
|
|
|
|
AnimationCollection* collection =
|
|
|
|
|
presContext->AnimationManager()->GetAnimationCollection(aFrame);
|
|
|
|
|
if (collection &&
|
Bug 1181392 part 5 - Remove use of IsFinishedTransition from AnimationCollection::HasAnimationOfProperty; r=dbaron
AnimationCollection::HasAnimationOfProperty uses IsFinishedTransition to filter
out transitions that should otherwise be ignored. This is used in the following
places:
1. nsLayoutUtils::HasAnimations
The is only used by nsIFrame::BuildDisplayListForStackingContext to see if
there are any opacity animations
For this case, simply returning *current* animations would be sufficient
(since finished but filling animations should have already filled in the
display opacity)
2. CommonAnimationManager::GetAnimationsForCompositor
This should really only return *current* animations--that is, animations that
are running or scheduled to run. Finished animations never run on the
compositor. Indeed, only *playing* animations run on the compositor but, as
we will see in some of the cases below, it is sometimes useful to know that
an animation *will* run on the compositor in the near future (e.g. so we can
pre-render content).
The places where GetAnimationsForCompositor is used are:
- When building layers to add animations to layers in nsDisplayList--in this
case we skip any animations that aren't playing so if
GetAnimationsForCompositor only returned current animations that would be
more than sufficient.
- In nsLayoutUtils::HasAnimationsForCompositor. This in turn is used:
- In ChooseScaleAndSetTransform to see if the transform is being animated
on the compositor. If so, it calls
nsLayoutUtils::ComputeSuitableScaleForAnimation (which also calls
GetAnimationsForCompositor) and passes the result to
GetMinAndMaxScaleForAnimationProperty which we have already adjusted in
part 4 of this patch series to only deal with *relevant* animations
Relevant animations include both current animations and in effect
animations but we don't run forwards-filling animations on the compositor
so GetAnimationsForCompositor should NOT return them. Current animations
should be enough. In fact, playing animations should be enough but we
might want to pre-render layers at a suitable size during their delay
phase so returning current animations is probably ok.
- In nsDisplayListBuilder::MarkOutOfFlowFrameForDisplay to add a fuzz
factor to the overflow rect for frames undergoing a transform animation
on the compositor. In this case too current animations should be
sufficient.
- In nsDisplayOpacity::NeedsActiveLayer to say "yes" if we are animating
opacity on the compositor. Presumably in this case it would be good to
say "yes" if the animation is in the delay phase too (as it currently
does). After the animation is finished, we should drop the layer, i.e.
current animations should be sufficient.
- In nsDisplayTransform::ShouldPrerenderTransformedContent. As with
nsDisplayOpacity::NeedsActiveLayer, we only need to pre-render
transformed content for animations that are current.
- In nsDisplayTransform::GetLayerState. As with
nsDisplayOpacity::NeedsActiveLayer, we only need to return active here
for current animations.
- In nsIFrame::IsTransformed. Here we test the display style to see if
there is a transform and also check if transform is being animated on the
compositor. As a result, we really only need HasAnimationsForCompositor
to return true for animations that are playing--otherwise the display
style will tell us if we're transformed or not. Returning true for all
current compositor animations (which is a superset of playing), however,
should not cause problems (we already return true for even more than
that).
- In nsIFrame::HasOpacityInternal which is much the same as
nsIFrame::IsTransformed and hence current should be fine.
3. AnimationCollection::CanThrottleAnimation
Here, HasAnimationOfProperty is used when looking for animations that would
disqualify us from throttling the animation by having an out-of-date layer
generation or being a transform animation that affects scroll and so requires
that we do the occasional main thread sample to update scrollbars.
It would seem like current animations are enough here too. One interesting
case is where we *had* a compositor animation but it has finished or been
cancelled. In that case, the animation won't be current and we should not
throttle the animation since we need to take it off its layer.
It turns out checking for current animations is still ok in this case too.
The reasoning is as follows:
- If the animation is newly-finished, we'll pick that up in
Animation::CanThrottle and return false then.
- If the animation is newly-idle then there are two cases:
If the cancelled animation was the only compositor animation then
AnimationCollection::CanPerformOnCompositorThread will notice that there
are no playing compositor animations and return false and
AnimationCollection::CanThrottleAnimation will never be called.
If there are other compositor animations running, then
AnimationCollection::CanThrottleAnimation will still return false because
whatever cancelled the animation will update the animation generation and
we'll notice the mismatch between the layer animation generation and the
animation generation on the collection.
Based on the above analysis it appears that making
AnimationCollection::HasAnimationOfProperty return only current animations (and
simulatneously renaming it to HasCurrentAnimationOfProperty) is safe. Indeed, in
effect, we already do this for transitions but not for animations. This patch
generalizes this behavior to all animations.
This patch also updates test_animations_omta.html since it was incorrectly
testing that a finished opacity animation was still running on the compositor.
Finished animations should not run on the compositor and the changes in this
patch cause that to happen. The reason we don't just update this test to check
for RunningOn.MainThread is that for opacity animations, unlike transform
animations, we can't detect if an opacity on a layer was set by animation or
not. As a result, for opacity animations we typically test the opacity on
either the main thread or compositor in order to allow for the case where an
animation-set opacity is still lingering on the compositor.
2015-08-07 06:29:36 +03:00
|
|
|
|
collection->HasCurrentAnimationOfProperty(aProperty)) {
|
2015-07-01 21:43:13 +03:00
|
|
|
|
return true;
|
2015-07-01 18:55:51 +03:00
|
|
|
|
}
|
2015-07-01 21:43:13 +03:00
|
|
|
|
collection =
|
|
|
|
|
presContext->TransitionManager()->GetAnimationCollection(aFrame);
|
|
|
|
|
if (collection &&
|
Bug 1181392 part 5 - Remove use of IsFinishedTransition from AnimationCollection::HasAnimationOfProperty; r=dbaron
AnimationCollection::HasAnimationOfProperty uses IsFinishedTransition to filter
out transitions that should otherwise be ignored. This is used in the following
places:
1. nsLayoutUtils::HasAnimations
The is only used by nsIFrame::BuildDisplayListForStackingContext to see if
there are any opacity animations
For this case, simply returning *current* animations would be sufficient
(since finished but filling animations should have already filled in the
display opacity)
2. CommonAnimationManager::GetAnimationsForCompositor
This should really only return *current* animations--that is, animations that
are running or scheduled to run. Finished animations never run on the
compositor. Indeed, only *playing* animations run on the compositor but, as
we will see in some of the cases below, it is sometimes useful to know that
an animation *will* run on the compositor in the near future (e.g. so we can
pre-render content).
The places where GetAnimationsForCompositor is used are:
- When building layers to add animations to layers in nsDisplayList--in this
case we skip any animations that aren't playing so if
GetAnimationsForCompositor only returned current animations that would be
more than sufficient.
- In nsLayoutUtils::HasAnimationsForCompositor. This in turn is used:
- In ChooseScaleAndSetTransform to see if the transform is being animated
on the compositor. If so, it calls
nsLayoutUtils::ComputeSuitableScaleForAnimation (which also calls
GetAnimationsForCompositor) and passes the result to
GetMinAndMaxScaleForAnimationProperty which we have already adjusted in
part 4 of this patch series to only deal with *relevant* animations
Relevant animations include both current animations and in effect
animations but we don't run forwards-filling animations on the compositor
so GetAnimationsForCompositor should NOT return them. Current animations
should be enough. In fact, playing animations should be enough but we
might want to pre-render layers at a suitable size during their delay
phase so returning current animations is probably ok.
- In nsDisplayListBuilder::MarkOutOfFlowFrameForDisplay to add a fuzz
factor to the overflow rect for frames undergoing a transform animation
on the compositor. In this case too current animations should be
sufficient.
- In nsDisplayOpacity::NeedsActiveLayer to say "yes" if we are animating
opacity on the compositor. Presumably in this case it would be good to
say "yes" if the animation is in the delay phase too (as it currently
does). After the animation is finished, we should drop the layer, i.e.
current animations should be sufficient.
- In nsDisplayTransform::ShouldPrerenderTransformedContent. As with
nsDisplayOpacity::NeedsActiveLayer, we only need to pre-render
transformed content for animations that are current.
- In nsDisplayTransform::GetLayerState. As with
nsDisplayOpacity::NeedsActiveLayer, we only need to return active here
for current animations.
- In nsIFrame::IsTransformed. Here we test the display style to see if
there is a transform and also check if transform is being animated on the
compositor. As a result, we really only need HasAnimationsForCompositor
to return true for animations that are playing--otherwise the display
style will tell us if we're transformed or not. Returning true for all
current compositor animations (which is a superset of playing), however,
should not cause problems (we already return true for even more than
that).
- In nsIFrame::HasOpacityInternal which is much the same as
nsIFrame::IsTransformed and hence current should be fine.
3. AnimationCollection::CanThrottleAnimation
Here, HasAnimationOfProperty is used when looking for animations that would
disqualify us from throttling the animation by having an out-of-date layer
generation or being a transform animation that affects scroll and so requires
that we do the occasional main thread sample to update scrollbars.
It would seem like current animations are enough here too. One interesting
case is where we *had* a compositor animation but it has finished or been
cancelled. In that case, the animation won't be current and we should not
throttle the animation since we need to take it off its layer.
It turns out checking for current animations is still ok in this case too.
The reasoning is as follows:
- If the animation is newly-finished, we'll pick that up in
Animation::CanThrottle and return false then.
- If the animation is newly-idle then there are two cases:
If the cancelled animation was the only compositor animation then
AnimationCollection::CanPerformOnCompositorThread will notice that there
are no playing compositor animations and return false and
AnimationCollection::CanThrottleAnimation will never be called.
If there are other compositor animations running, then
AnimationCollection::CanThrottleAnimation will still return false because
whatever cancelled the animation will update the animation generation and
we'll notice the mismatch between the layer animation generation and the
animation generation on the collection.
Based on the above analysis it appears that making
AnimationCollection::HasAnimationOfProperty return only current animations (and
simulatneously renaming it to HasCurrentAnimationOfProperty) is safe. Indeed, in
effect, we already do this for transitions but not for animations. This patch
generalizes this behavior to all animations.
This patch also updates test_animations_omta.html since it was incorrectly
testing that a finished opacity animation was still running on the compositor.
Finished animations should not run on the compositor and the changes in this
patch cause that to happen. The reason we don't just update this test to check
for RunningOn.MainThread is that for opacity animations, unlike transform
animations, we can't detect if an opacity on a layer was set by animation or
not. As a result, for opacity animations we typically test the opacity on
either the main thread or compositor in order to allow for the case where an
animation-set opacity is still lingering on the compositor.
2015-08-07 06:29:36 +03:00
|
|
|
|
collection->HasCurrentAnimationOfProperty(aProperty)) {
|
2015-07-01 21:43:13 +03:00
|
|
|
|
return true;
|
2015-07-01 18:55:51 +03:00
|
|
|
|
}
|
|
|
|
|
return false;
|
2012-12-12 01:12:43 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-16 22:43:04 +04:00
|
|
|
|
bool
|
2015-07-01 21:43:13 +03:00
|
|
|
|
nsLayoutUtils::HasCurrentAnimations(const nsIFrame* aFrame)
|
2014-06-16 22:43:04 +04:00
|
|
|
|
{
|
2015-07-01 21:43:13 +03:00
|
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
|
|
|
|
AnimationCollection* collection =
|
|
|
|
|
presContext->AnimationManager()->GetAnimationCollection(aFrame);
|
|
|
|
|
return collection &&
|
|
|
|
|
collection->HasCurrentAnimations();
|
|
|
|
|
}
|
2014-06-16 22:43:04 +04:00
|
|
|
|
|
2015-07-01 21:43:13 +03:00
|
|
|
|
bool
|
|
|
|
|
nsLayoutUtils::HasCurrentTransitions(const nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
2015-04-21 04:22:10 +03:00
|
|
|
|
AnimationCollection* collection =
|
2015-07-01 21:43:13 +03:00
|
|
|
|
presContext->TransitionManager()->GetAnimationCollection(aFrame);
|
|
|
|
|
return collection &&
|
|
|
|
|
collection->HasCurrentAnimations();
|
2014-06-16 22:43:04 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-02 10:14:14 +04:00
|
|
|
|
bool
|
2015-07-01 18:55:51 +03:00
|
|
|
|
nsLayoutUtils::HasCurrentAnimationsForProperties(const nsIFrame* aFrame,
|
2015-04-06 05:53:51 +03:00
|
|
|
|
const nsCSSProperty* aProperties,
|
|
|
|
|
size_t aPropertyCount)
|
2014-10-02 10:14:14 +04:00
|
|
|
|
{
|
2015-07-01 21:43:13 +03:00
|
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
|
|
|
|
AnimationCollection* collection =
|
|
|
|
|
presContext->AnimationManager()->GetAnimationCollection(aFrame);
|
|
|
|
|
if (collection &&
|
|
|
|
|
collection->HasCurrentAnimationsForProperties(aProperties,
|
|
|
|
|
aPropertyCount)) {
|
|
|
|
|
return true;
|
2015-07-01 18:55:51 +03:00
|
|
|
|
}
|
2015-07-01 21:43:13 +03:00
|
|
|
|
collection =
|
|
|
|
|
presContext->TransitionManager()->GetAnimationCollection(aFrame);
|
|
|
|
|
if (collection &&
|
|
|
|
|
collection->HasCurrentAnimationsForProperties(aProperties,
|
|
|
|
|
aPropertyCount)) {
|
|
|
|
|
return true;
|
2014-10-02 10:14:14 +04:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-20 07:39:26 +04:00
|
|
|
|
static float
|
2015-05-06 09:52:20 +03:00
|
|
|
|
GetSuitableScale(float aMaxScale, float aMinScale,
|
|
|
|
|
nscoord aVisibleDimension, nscoord aDisplayDimension)
|
2014-02-18 18:58:01 +04:00
|
|
|
|
{
|
2015-05-06 09:52:20 +03:00
|
|
|
|
float displayVisibleRatio = float(aDisplayDimension) /
|
|
|
|
|
float(aVisibleDimension);
|
|
|
|
|
// We want to rasterize based on the largest scale used during the
|
|
|
|
|
// transform animation, unless that would make us rasterize something
|
|
|
|
|
// larger than the screen. But we never want to go smaller than the
|
|
|
|
|
// minimum scale over the animation.
|
|
|
|
|
return std::max(std::min(aMaxScale, displayVisibleRatio), aMinScale);
|
2014-02-18 18:58:01 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-20 07:39:26 +04:00
|
|
|
|
static void
|
2015-07-01 18:55:51 +03:00
|
|
|
|
GetMinAndMaxScaleForAnimationProperty(const nsIFrame* aFrame,
|
2015-04-21 04:22:10 +03:00
|
|
|
|
AnimationCollection* aAnimations,
|
2014-06-20 07:39:26 +04:00
|
|
|
|
gfxSize& aMaxScale,
|
|
|
|
|
gfxSize& aMinScale)
|
2012-12-22 01:58:17 +04:00
|
|
|
|
{
|
2015-04-21 04:22:10 +03:00
|
|
|
|
for (size_t animIdx = aAnimations->mAnimations.Length(); animIdx-- != 0; ) {
|
|
|
|
|
dom::Animation* anim = aAnimations->mAnimations[animIdx];
|
2015-08-07 06:29:36 +03:00
|
|
|
|
if (!anim->IsRelevant()) {
|
2014-06-20 07:39:26 +04:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-04-30 16:06:43 +03:00
|
|
|
|
dom::KeyframeEffectReadOnly* effect = anim->GetEffect();
|
2015-04-15 02:48:21 +03:00
|
|
|
|
for (size_t propIdx = effect->Properties().Length(); propIdx-- != 0; ) {
|
|
|
|
|
AnimationProperty& prop = effect->Properties()[propIdx];
|
2014-06-20 07:39:26 +04:00
|
|
|
|
if (prop.mProperty == eCSSProperty_transform) {
|
|
|
|
|
for (uint32_t segIdx = prop.mSegments.Length(); segIdx-- != 0; ) {
|
|
|
|
|
AnimationPropertySegment& segment = prop.mSegments[segIdx];
|
2015-07-20 05:30:40 +03:00
|
|
|
|
gfxSize from = segment.mFromValue.GetScaleValue(aFrame);
|
2014-06-20 07:39:26 +04:00
|
|
|
|
aMaxScale.width = std::max<float>(aMaxScale.width, from.width);
|
|
|
|
|
aMaxScale.height = std::max<float>(aMaxScale.height, from.height);
|
|
|
|
|
aMinScale.width = std::min<float>(aMinScale.width, from.width);
|
|
|
|
|
aMinScale.height = std::min<float>(aMinScale.height, from.height);
|
2015-07-20 05:30:40 +03:00
|
|
|
|
gfxSize to = segment.mToValue.GetScaleValue(aFrame);
|
2014-06-20 07:39:26 +04:00
|
|
|
|
aMaxScale.width = std::max<float>(aMaxScale.width, to.width);
|
|
|
|
|
aMaxScale.height = std::max<float>(aMaxScale.height, to.height);
|
|
|
|
|
aMinScale.width = std::min<float>(aMinScale.width, to.width);
|
|
|
|
|
aMinScale.height = std::min<float>(aMinScale.height, to.height);
|
2012-12-22 01:58:17 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-20 07:39:26 +04:00
|
|
|
|
}
|
2014-02-18 18:58:01 +04:00
|
|
|
|
|
2014-06-20 07:39:26 +04:00
|
|
|
|
gfxSize
|
2015-07-01 18:55:51 +03:00
|
|
|
|
nsLayoutUtils::ComputeSuitableScaleForAnimation(const nsIFrame* aFrame,
|
2015-05-06 09:52:20 +03:00
|
|
|
|
const nsSize& aVisibleSize,
|
|
|
|
|
const nsSize& aDisplaySize)
|
2014-06-20 07:39:26 +04:00
|
|
|
|
{
|
2014-12-04 08:21:42 +03:00
|
|
|
|
gfxSize maxScale(std::numeric_limits<gfxFloat>::min(),
|
|
|
|
|
std::numeric_limits<gfxFloat>::min());
|
|
|
|
|
gfxSize minScale(std::numeric_limits<gfxFloat>::max(),
|
|
|
|
|
std::numeric_limits<gfxFloat>::max());
|
2015-07-01 18:55:51 +03:00
|
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
2014-06-20 07:39:26 +04:00
|
|
|
|
|
2015-04-21 04:22:10 +03:00
|
|
|
|
AnimationCollection* animations =
|
2015-07-01 18:55:51 +03:00
|
|
|
|
presContext->AnimationManager()->GetAnimationsForCompositor(
|
|
|
|
|
aFrame, eCSSProperty_transform);
|
2015-04-01 06:23:24 +03:00
|
|
|
|
if (animations) {
|
2015-07-01 18:55:51 +03:00
|
|
|
|
GetMinAndMaxScaleForAnimationProperty(aFrame, animations,
|
2015-04-01 06:23:24 +03:00
|
|
|
|
maxScale, minScale);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
animations =
|
2015-07-01 18:55:51 +03:00
|
|
|
|
presContext->TransitionManager()->GetAnimationsForCompositor(
|
|
|
|
|
aFrame, eCSSProperty_transform);
|
2015-04-01 06:23:24 +03:00
|
|
|
|
if (animations) {
|
2015-07-01 18:55:51 +03:00
|
|
|
|
GetMinAndMaxScaleForAnimationProperty(aFrame, animations,
|
2015-04-01 06:23:24 +03:00
|
|
|
|
maxScale, minScale);
|
|
|
|
|
}
|
2012-12-22 01:58:17 +04:00
|
|
|
|
|
2014-12-04 08:21:42 +03:00
|
|
|
|
if (maxScale.width == std::numeric_limits<gfxFloat>::min()) {
|
|
|
|
|
// We didn't encounter a transform
|
2015-05-06 09:52:20 +03:00
|
|
|
|
return gfxSize(1.0, 1.0);
|
2014-12-04 08:21:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-06 09:52:20 +03:00
|
|
|
|
return gfxSize(GetSuitableScale(maxScale.width, minScale.width,
|
|
|
|
|
aVisibleSize.width, aDisplaySize.width),
|
|
|
|
|
GetSuitableScale(maxScale.height, minScale.height,
|
|
|
|
|
aVisibleSize.height, aDisplaySize.height));
|
2012-12-22 01:58:17 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-31 21:28:22 +04:00
|
|
|
|
bool
|
2013-05-23 11:09:26 +04:00
|
|
|
|
nsLayoutUtils::AreAsyncAnimationsEnabled()
|
2012-07-31 21:28:22 +04:00
|
|
|
|
{
|
2013-05-23 11:09:26 +04:00
|
|
|
|
static bool sAreAsyncAnimationsEnabled;
|
|
|
|
|
static bool sAsyncPrefCached = false;
|
2012-07-31 21:28:22 +04:00
|
|
|
|
|
2013-05-23 11:09:26 +04:00
|
|
|
|
if (!sAsyncPrefCached) {
|
|
|
|
|
sAsyncPrefCached = true;
|
|
|
|
|
Preferences::AddBoolVarCache(&sAreAsyncAnimationsEnabled,
|
|
|
|
|
"layers.offmainthreadcomposition.async-animations");
|
2012-07-31 21:28:22 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-23 11:09:26 +04:00
|
|
|
|
return sAreAsyncAnimationsEnabled &&
|
2012-08-26 05:27:28 +04:00
|
|
|
|
gfxPlatform::OffMainThreadCompositingEnabled();
|
2012-07-31 21:28:22 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-07 00:33:23 +04: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 18:28:46 +04:00
|
|
|
|
bool
|
|
|
|
|
nsLayoutUtils::UseBackgroundNearestFiltering()
|
|
|
|
|
{
|
|
|
|
|
static bool sUseBackgroundNearestFilteringEnabled;
|
|
|
|
|
static bool sUseBackgroundNearestFilteringPrefInitialised = false;
|
|
|
|
|
|
|
|
|
|
if (!sUseBackgroundNearestFilteringPrefInitialised) {
|
|
|
|
|
sUseBackgroundNearestFilteringPrefInitialised = true;
|
2012-10-03 04:18:48 +04:00
|
|
|
|
sUseBackgroundNearestFilteringEnabled =
|
|
|
|
|
Preferences::GetBool("gfx.filter.nearest.force-enabled", false);
|
2012-04-24 18:28:46 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sUseBackgroundNearestFilteringEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-03 18:05:55 +04:00
|
|
|
|
bool
|
|
|
|
|
nsLayoutUtils::GPUImageScalingEnabled()
|
|
|
|
|
{
|
|
|
|
|
static bool sGPUImageScalingEnabled;
|
|
|
|
|
static bool sGPUImageScalingPrefInitialised = false;
|
|
|
|
|
|
|
|
|
|
if (!sGPUImageScalingPrefInitialised) {
|
|
|
|
|
sGPUImageScalingPrefInitialised = true;
|
2012-10-03 04:18:48 +04:00
|
|
|
|
sGPUImageScalingEnabled =
|
|
|
|
|
Preferences::GetBool("layout.gpu-image-scaling.enabled", false);
|
2012-05-03 18:05:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sGPUImageScalingEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-31 05:33:17 +04:00
|
|
|
|
bool
|
|
|
|
|
nsLayoutUtils::AnimatedImageLayersEnabled()
|
|
|
|
|
{
|
|
|
|
|
static bool sAnimatedImageLayersEnabled;
|
|
|
|
|
static bool sAnimatedImageLayersPrefCached = false;
|
|
|
|
|
|
|
|
|
|
if (!sAnimatedImageLayersPrefCached) {
|
|
|
|
|
sAnimatedImageLayersPrefCached = true;
|
|
|
|
|
Preferences::AddBoolVarCache(&sAnimatedImageLayersEnabled,
|
|
|
|
|
"layout.animated-image-layers.enabled",
|
|
|
|
|
false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sAnimatedImageLayersEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-23 02:08:33 +04:00
|
|
|
|
bool
|
|
|
|
|
nsLayoutUtils::CSSFiltersEnabled()
|
|
|
|
|
{
|
|
|
|
|
static bool sCSSFiltersEnabled;
|
|
|
|
|
static bool sCSSFiltersPrefCached = false;
|
|
|
|
|
|
|
|
|
|
if (!sCSSFiltersPrefCached) {
|
|
|
|
|
sCSSFiltersPrefCached = true;
|
|
|
|
|
Preferences::AddBoolVarCache(&sCSSFiltersEnabled,
|
|
|
|
|
"layout.css.filters.enabled",
|
|
|
|
|
false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sCSSFiltersEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-28 03:56:00 +04:00
|
|
|
|
bool
|
|
|
|
|
nsLayoutUtils::CSSClipPathShapesEnabled()
|
|
|
|
|
{
|
|
|
|
|
static bool sCSSClipPathShapesEnabled;
|
|
|
|
|
static bool sCSSClipPathShapesPrefCached = false;
|
|
|
|
|
|
|
|
|
|
if (!sCSSClipPathShapesPrefCached) {
|
|
|
|
|
sCSSClipPathShapesPrefCached = true;
|
|
|
|
|
Preferences::AddBoolVarCache(&sCSSClipPathShapesEnabled,
|
|
|
|
|
"layout.css.clip-path-shapes.enabled",
|
|
|
|
|
false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sCSSClipPathShapesEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-03 22:48:41 +04:00
|
|
|
|
bool
|
|
|
|
|
nsLayoutUtils::UnsetValueEnabled()
|
|
|
|
|
{
|
|
|
|
|
static bool sUnsetValueEnabled;
|
|
|
|
|
static bool sUnsetValuePrefCached = false;
|
|
|
|
|
|
|
|
|
|
if (!sUnsetValuePrefCached) {
|
|
|
|
|
sUnsetValuePrefCached = true;
|
|
|
|
|
Preferences::AddBoolVarCache(&sUnsetValueEnabled,
|
|
|
|
|
"layout.css.unset-value.enabled",
|
|
|
|
|
false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sUnsetValueEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-28 00:56:32 +04:00
|
|
|
|
bool
|
|
|
|
|
nsLayoutUtils::IsTextAlignTrueValueEnabled()
|
|
|
|
|
{
|
|
|
|
|
static bool sTextAlignTrueValueEnabled;
|
|
|
|
|
static bool sTextAlignTrueValueEnabledPrefCached = false;
|
|
|
|
|
|
|
|
|
|
if (!sTextAlignTrueValueEnabledPrefCached) {
|
|
|
|
|
sTextAlignTrueValueEnabledPrefCached = true;
|
|
|
|
|
Preferences::AddBoolVarCache(&sTextAlignTrueValueEnabled,
|
|
|
|
|
TEXT_ALIGN_TRUE_ENABLED_PREF_NAME,
|
|
|
|
|
false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sTextAlignTrueValueEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-16 01:03:49 +04:00
|
|
|
|
void
|
|
|
|
|
nsLayoutUtils::UnionChildOverflow(nsIFrame* aFrame,
|
2014-04-03 12:25:03 +04:00
|
|
|
|
nsOverflowAreas& aOverflowAreas,
|
|
|
|
|
FrameChildListIDs aSkipChildLists)
|
2011-06-16 01:03:49 +04:00
|
|
|
|
{
|
2012-01-19 00:04:51 +04:00
|
|
|
|
// Iterate over all children except pop-ups.
|
2014-04-03 12:25:03 +04:00
|
|
|
|
FrameChildListIDs skip = aSkipChildLists |
|
|
|
|
|
nsIFrame::kSelectPopupList | nsIFrame::kPopupList;
|
2011-06-16 01:03:49 +04:00
|
|
|
|
for (nsIFrame::ChildListIterator childLists(aFrame);
|
|
|
|
|
!childLists.IsDone(); childLists.Next()) {
|
2012-01-19 00:04:51 +04:00
|
|
|
|
if (skip.Contains(childLists.CurrentID())) {
|
2011-06-16 01:03:49 +04:00
|
|
|
|
continue;
|
2012-01-19 00:04:51 +04:00
|
|
|
|
}
|
2011-06-16 01:03:49 +04: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 20:45:14 +03: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-16 02:20:19 +03:00
|
|
|
|
/**
|
|
|
|
|
* A namespace class for static layout utilities.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-08-08 23:56:08 +04:00
|
|
|
|
bool
|
2013-11-13 22:22:24 +04:00
|
|
|
|
nsLayoutUtils::FindIDFor(const nsIContent* aContent, ViewID* aOutViewId)
|
2013-08-08 23:56:08 +04:00
|
|
|
|
{
|
|
|
|
|
void* scrollIdProperty = aContent->GetProperty(nsGkAtoms::RemoteId);
|
|
|
|
|
if (scrollIdProperty) {
|
|
|
|
|
*aOutViewId = *static_cast<ViewID*>(scrollIdProperty);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-13 20:45:14 +03:00
|
|
|
|
ViewID
|
2013-11-09 04:07:00 +04:00
|
|
|
|
nsLayoutUtils::FindOrCreateIDFor(nsIContent* aContent)
|
2011-01-13 20:45:14 +03:00
|
|
|
|
{
|
|
|
|
|
ViewID scrollId;
|
|
|
|
|
|
2013-08-08 23:56:08 +04:00
|
|
|
|
if (!FindIDFor(aContent, &scrollId)) {
|
2013-11-09 04:07:00 +04:00
|
|
|
|
scrollId = sScrollIdCounter++;
|
2011-01-13 20:45:14 +03:00
|
|
|
|
aContent->SetProperty(nsGkAtoms::RemoteId, new ViewID(scrollId),
|
|
|
|
|
DestroyViewID);
|
|
|
|
|
GetContentMap().Put(scrollId, aContent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return scrollId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIContent*
|
|
|
|
|
nsLayoutUtils::FindContentFor(ViewID aId)
|
|
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
|
MOZ_ASSERT(aId != FrameMetrics::NULL_SCROLL_ID,
|
|
|
|
|
"Cannot find a content element in map for null IDs.");
|
2011-01-13 20:45:14 +03:00
|
|
|
|
nsIContent* content;
|
|
|
|
|
bool exists = GetContentMap().Get(aId, &content);
|
|
|
|
|
|
|
|
|
|
if (exists) {
|
|
|
|
|
return content;
|
|
|
|
|
} else {
|
2012-07-30 18:20:58 +04:00
|
|
|
|
return nullptr;
|
2011-01-13 20:45:14 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-30 22:03:42 +04:00
|
|
|
|
nsIScrollableFrame*
|
|
|
|
|
nsLayoutUtils::FindScrollableFrameFor(ViewID aId)
|
|
|
|
|
{
|
|
|
|
|
nsIContent* content = FindContentFor(aId);
|
|
|
|
|
if (!content) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIFrame* scrolledFrame = content->GetPrimaryFrame();
|
|
|
|
|
if (scrolledFrame && content->OwnerDoc()->GetRootElement() == content) {
|
|
|
|
|
// The content is the root element of a subdocument, so return the root scrollable
|
|
|
|
|
// for the subdocument.
|
|
|
|
|
scrolledFrame = scrolledFrame->PresContext()->PresShell()->GetRootScrollFrame();
|
|
|
|
|
}
|
|
|
|
|
return scrolledFrame ? scrolledFrame->GetScrollTargetFrame() : nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-21 20:06:02 +04:00
|
|
|
|
static nsRect
|
|
|
|
|
ApplyRectMultiplier(nsRect aRect, float aMultiplier)
|
|
|
|
|
{
|
|
|
|
|
if (aMultiplier == 1.0f) {
|
|
|
|
|
return aRect;
|
|
|
|
|
}
|
|
|
|
|
float newWidth = aRect.width * aMultiplier;
|
|
|
|
|
float newHeight = aRect.height * aMultiplier;
|
|
|
|
|
float newX = aRect.x - ((newWidth - aRect.width) / 2.0f);
|
|
|
|
|
float newY = aRect.y - ((newHeight - aRect.height) / 2.0f);
|
|
|
|
|
// Rounding doesn't matter too much here, do a round-in
|
|
|
|
|
return nsRect(ceil(newX), ceil(newY), floor(newWidth), floor(newHeight));
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-04 23:51:10 +03:00
|
|
|
|
bool
|
|
|
|
|
nsLayoutUtils::UsesAsyncScrolling(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
|
// We always have async scrolling for android
|
|
|
|
|
return true;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return AsyncPanZoomEnabled(aFrame);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
nsLayoutUtils::AsyncPanZoomEnabled(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
// We use this as a shortcut, since if the compositor will never use APZ,
|
|
|
|
|
// no widget will either.
|
2015-07-16 00:13:22 +03:00
|
|
|
|
if (!gfxPlatform::AsyncPanZoomEnabled()) {
|
2015-06-04 23:51:10 +03:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIFrame *frame = nsLayoutUtils::GetDisplayRootFrame(aFrame);
|
|
|
|
|
nsIWidget* widget = frame->GetNearestWidget();
|
|
|
|
|
if (!widget) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return widget->AsyncPanZoomEnabled();
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-17 08:59:29 +03:00
|
|
|
|
// Return the maximum displayport size, based on the LayerManager's maximum
|
|
|
|
|
// supported texture size. The result is in app units.
|
|
|
|
|
static nscoord
|
|
|
|
|
GetMaxDisplayPortSize(nsIContent* aContent)
|
|
|
|
|
{
|
|
|
|
|
MOZ_ASSERT(!gfxPrefs::LayersTilesEnabled(), "Do not clamp displayports if tiling is enabled");
|
|
|
|
|
|
|
|
|
|
nsIFrame* frame = aContent->GetPrimaryFrame();
|
|
|
|
|
if (!frame) {
|
|
|
|
|
return nscoord_MAX;
|
|
|
|
|
}
|
|
|
|
|
frame = nsLayoutUtils::GetDisplayRootFrame(frame);
|
|
|
|
|
|
|
|
|
|
nsIWidget* widget = frame->GetNearestWidget();
|
|
|
|
|
if (!widget) {
|
|
|
|
|
return nscoord_MAX;
|
|
|
|
|
}
|
|
|
|
|
LayerManager* lm = widget->GetLayerManager();
|
|
|
|
|
if (!lm) {
|
|
|
|
|
return nscoord_MAX;
|
|
|
|
|
}
|
|
|
|
|
nsPresContext* presContext = frame->PresContext();
|
|
|
|
|
|
2015-03-23 22:34:21 +03:00
|
|
|
|
int32_t maxSizeInDevPixels = lm->GetMaxTextureSize();
|
|
|
|
|
if (maxSizeInDevPixels < 0 || maxSizeInDevPixels == INT_MAX) {
|
|
|
|
|
return nscoord_MAX;
|
|
|
|
|
}
|
2015-03-17 08:59:29 +03:00
|
|
|
|
return presContext->DevPixelsToAppUnits(maxSizeInDevPixels);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-21 20:06:03 +04:00
|
|
|
|
static nsRect
|
|
|
|
|
GetDisplayPortFromRectData(nsIContent* aContent,
|
|
|
|
|
DisplayPortPropertyData* aRectData,
|
|
|
|
|
float aMultiplier)
|
|
|
|
|
{
|
|
|
|
|
// In the case where the displayport is set as a rect, we assume it is
|
|
|
|
|
// already aligned and clamped as necessary. The burden to do that is
|
|
|
|
|
// on the setter of the displayport. In practice very few places set the
|
|
|
|
|
// displayport directly as a rect (mostly tests). We still do need to
|
|
|
|
|
// expand it by the multiplier though.
|
|
|
|
|
return ApplyRectMultiplier(aRectData->mRect, aMultiplier);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static nsRect
|
|
|
|
|
GetDisplayPortFromMarginsData(nsIContent* aContent,
|
|
|
|
|
DisplayPortMarginsPropertyData* aMarginsData,
|
|
|
|
|
float aMultiplier)
|
|
|
|
|
{
|
|
|
|
|
// In the case where the displayport is set via margins, we apply the margins
|
|
|
|
|
// to a base rect. Then we align the expanded rect based on the alignment
|
|
|
|
|
// requested, further expand the rect by the multiplier, and finally, clamp it
|
|
|
|
|
// to the size of the scrollable rect.
|
|
|
|
|
|
|
|
|
|
nsRect base;
|
|
|
|
|
if (nsRect* baseData = static_cast<nsRect*>(aContent->GetProperty(nsGkAtoms::DisplayPortBase))) {
|
|
|
|
|
base = *baseData;
|
|
|
|
|
} else {
|
|
|
|
|
NS_WARNING("Attempting to get a margins-based displayport with no base data!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIFrame* frame = aContent->GetPrimaryFrame();
|
|
|
|
|
if (!frame) {
|
|
|
|
|
// Turns out we can't really compute it. Oops. We still should return
|
|
|
|
|
// something sane. Note that although we can apply the multiplier on the
|
|
|
|
|
// base rect here, we can't tile-align or clamp the rect without a frame.
|
|
|
|
|
NS_WARNING("Attempting to get a displayport from a content with no primary frame!");
|
|
|
|
|
return ApplyRectMultiplier(base, aMultiplier);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool isRoot = false;
|
|
|
|
|
if (aContent->OwnerDoc()->GetRootElement() == aContent) {
|
|
|
|
|
// We want the scroll frame, the root scroll frame differs from all
|
|
|
|
|
// others in that the primary frame is not the scroll frame.
|
|
|
|
|
frame = frame->PresContext()->PresShell()->GetRootScrollFrame();
|
2015-02-13 04:49:10 +03:00
|
|
|
|
if (!frame) {
|
|
|
|
|
// If there is no root scrollframe, just exit.
|
|
|
|
|
return ApplyRectMultiplier(base, aMultiplier);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-21 20:06:03 +04:00
|
|
|
|
isRoot = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsPoint scrollPos;
|
|
|
|
|
if (nsIScrollableFrame* scrollableFrame = frame->GetScrollTargetFrame()) {
|
|
|
|
|
scrollPos = scrollableFrame->GetScrollPosition();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsPresContext* presContext = frame->PresContext();
|
|
|
|
|
int32_t auPerDevPixel = presContext->AppUnitsPerDevPixel();
|
|
|
|
|
|
2015-03-06 21:54:10 +03:00
|
|
|
|
LayoutDeviceToScreenScale2D res(presContext->PresShell()->GetCumulativeResolution()
|
|
|
|
|
* nsLayoutUtils::GetTransformToAncestorScale(frame));
|
2014-10-24 23:49:38 +04:00
|
|
|
|
|
|
|
|
|
// First convert the base rect to screen pixels
|
2015-03-06 21:54:10 +03:00
|
|
|
|
LayoutDeviceToScreenScale2D parentRes = res;
|
2014-05-21 20:06:03 +04:00
|
|
|
|
if (isRoot) {
|
|
|
|
|
// the base rect for root scroll frames is specified in the parent document
|
|
|
|
|
// coordinate space, so it doesn't include the local resolution.
|
2015-03-07 02:07:59 +03:00
|
|
|
|
float localRes = presContext->PresShell()->GetResolution();
|
|
|
|
|
parentRes.xScale /= localRes;
|
|
|
|
|
parentRes.yScale /= localRes;
|
2014-05-21 20:06:03 +04:00
|
|
|
|
}
|
2014-10-24 23:49:38 +04:00
|
|
|
|
ScreenRect screenRect = LayoutDeviceRect::FromAppUnits(base, auPerDevPixel)
|
|
|
|
|
* parentRes;
|
2014-05-21 20:06:03 +04:00
|
|
|
|
|
2015-03-17 08:59:29 +03:00
|
|
|
|
if (gfxPrefs::LayersTilesEnabled()) {
|
|
|
|
|
// Note on the correctness of applying the alignment in Screen space:
|
|
|
|
|
// The correct space to apply the alignment in would be Layer space, but
|
|
|
|
|
// we don't necessarily know the scale to convert to Layer space at this
|
|
|
|
|
// point because Layout may not yet have chosen the resolution at which to
|
|
|
|
|
// render (it chooses that in FrameLayerBuilder, but this can be called
|
|
|
|
|
// during display list building). Therefore, we perform the alignment in
|
|
|
|
|
// Screen space, which basically assumes that Layout chose to render at
|
|
|
|
|
// screen resolution; since this is what Layout does most of the time,
|
|
|
|
|
// this is a good approximation. A proper solution would involve moving
|
|
|
|
|
// the choosing of the resolution to display-list building time.
|
|
|
|
|
int alignmentX = gfxPlatform::GetPlatform()->GetTileWidth();
|
|
|
|
|
int alignmentY = gfxPlatform::GetPlatform()->GetTileHeight();
|
|
|
|
|
|
|
|
|
|
// Expand the rect by the margins
|
|
|
|
|
screenRect.Inflate(aMarginsData->mMargins);
|
|
|
|
|
|
2014-05-21 20:06:03 +04:00
|
|
|
|
// Inflate the rectangle by 1 so that we always push to the next tile
|
|
|
|
|
// boundary. This is desirable to stop from having a rectangle with a
|
|
|
|
|
// moving origin occasionally being smaller when it coincidentally lines
|
|
|
|
|
// up to tile boundaries.
|
2014-10-24 23:49:38 +04:00
|
|
|
|
screenRect.Inflate(1);
|
2014-05-21 20:06:03 +04:00
|
|
|
|
|
|
|
|
|
// Avoid division by zero.
|
2014-11-13 01:54:29 +03:00
|
|
|
|
if (alignmentX == 0) {
|
|
|
|
|
alignmentX = 1;
|
2014-05-21 20:06:03 +04:00
|
|
|
|
}
|
2014-11-13 01:54:29 +03:00
|
|
|
|
if (alignmentY == 0) {
|
|
|
|
|
alignmentY = 1;
|
2014-05-21 20:06:03 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-24 23:49:38 +04:00
|
|
|
|
ScreenPoint scrollPosScreen = LayoutDevicePoint::FromAppUnits(scrollPos, auPerDevPixel)
|
|
|
|
|
* res;
|
2014-05-21 20:06:03 +04:00
|
|
|
|
|
2014-10-24 23:49:38 +04:00
|
|
|
|
screenRect += scrollPosScreen;
|
2014-11-13 01:54:29 +03:00
|
|
|
|
float x = alignmentX * floor(screenRect.x / alignmentX);
|
|
|
|
|
float y = alignmentY * floor(screenRect.y / alignmentY);
|
|
|
|
|
float w = alignmentX * ceil(screenRect.XMost() / alignmentX) - x;
|
|
|
|
|
float h = alignmentY * ceil(screenRect.YMost() / alignmentY) - y;
|
2014-10-24 23:49:38 +04:00
|
|
|
|
screenRect = ScreenRect(x, y, w, h);
|
|
|
|
|
screenRect -= scrollPosScreen;
|
2015-03-17 08:59:29 +03:00
|
|
|
|
} else {
|
|
|
|
|
nscoord maxSizeInAppUnits = GetMaxDisplayPortSize(aContent);
|
|
|
|
|
if (maxSizeInAppUnits == nscoord_MAX) {
|
|
|
|
|
// Pick a safe maximum displayport size for sanity purposes. This is the
|
|
|
|
|
// lowest maximum texture size on tileless-platforms (Windows, D3D10).
|
|
|
|
|
maxSizeInAppUnits = presContext->DevPixelsToAppUnits(8192);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Find the maximum size in screen pixels.
|
|
|
|
|
int32_t maxSizeInDevPixels = presContext->AppUnitsToDevPixels(maxSizeInAppUnits);
|
|
|
|
|
int32_t maxWidthInScreenPixels = floor(double(maxSizeInDevPixels) * res.xScale);
|
|
|
|
|
int32_t maxHeightInScreenPixels = floor(double(maxSizeInDevPixels) * res.yScale);
|
|
|
|
|
|
|
|
|
|
// For each axis, inflate the margins up to the maximum size.
|
|
|
|
|
const ScreenMargin& margins = aMarginsData->mMargins;
|
|
|
|
|
if (screenRect.height < maxHeightInScreenPixels) {
|
|
|
|
|
int32_t budget = maxHeightInScreenPixels - screenRect.height;
|
|
|
|
|
|
2015-08-11 01:30:45 +03:00
|
|
|
|
float top = std::min(margins.top, float(budget));
|
|
|
|
|
float bottom = std::min(margins.bottom, budget - top);
|
2015-03-17 08:59:29 +03:00
|
|
|
|
screenRect.y -= top;
|
2015-08-11 01:30:45 +03:00
|
|
|
|
screenRect.height += top + bottom;
|
2015-03-17 08:59:29 +03:00
|
|
|
|
}
|
|
|
|
|
if (screenRect.width < maxWidthInScreenPixels) {
|
|
|
|
|
int32_t budget = maxWidthInScreenPixels - screenRect.width;
|
|
|
|
|
|
2015-08-11 01:30:45 +03:00
|
|
|
|
float left = std::min(margins.left, float(budget));
|
|
|
|
|
float right = std::min(margins.right, budget - left);
|
2015-03-17 08:59:29 +03:00
|
|
|
|
screenRect.x -= left;
|
2015-08-11 01:30:45 +03:00
|
|
|
|
screenRect.width += left + right;
|
2015-03-17 08:59:29 +03:00
|
|
|
|
}
|
2014-05-21 20:06:03 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-17 08:59:29 +03:00
|
|
|
|
// Convert the aligned rect back into app units.
|
2014-10-24 23:49:38 +04:00
|
|
|
|
nsRect result = LayoutDeviceRect::ToAppUnits(screenRect / res, auPerDevPixel);
|
2014-05-21 20:06:03 +04:00
|
|
|
|
|
|
|
|
|
// Expand it for the low-res buffer if needed
|
|
|
|
|
result = ApplyRectMultiplier(result, aMultiplier);
|
|
|
|
|
|
|
|
|
|
// Finally, clamp it to the expanded scrollable rect.
|
|
|
|
|
nsRect expandedScrollableRect = nsLayoutUtils::CalculateExpandedScrollableRect(frame);
|
|
|
|
|
result = expandedScrollableRect.Intersect(result + scrollPos) - scrollPos;
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-21 20:06:02 +04:00
|
|
|
|
static bool
|
2014-05-21 20:06:03 +04:00
|
|
|
|
GetDisplayPortImpl(nsIContent* aContent, nsRect *aResult, float aMultiplier)
|
2011-03-16 02:20:19 +03:00
|
|
|
|
{
|
2014-03-27 05:46:23 +04:00
|
|
|
|
DisplayPortPropertyData* rectData =
|
|
|
|
|
static_cast<DisplayPortPropertyData*>(aContent->GetProperty(nsGkAtoms::DisplayPort));
|
|
|
|
|
DisplayPortMarginsPropertyData* marginsData =
|
|
|
|
|
static_cast<DisplayPortMarginsPropertyData*>(aContent->GetProperty(nsGkAtoms::DisplayPortMargins));
|
2014-05-21 20:06:03 +04:00
|
|
|
|
|
2014-03-27 05:46:23 +04:00
|
|
|
|
if (!rectData && !marginsData) {
|
2014-05-21 20:06:03 +04:00
|
|
|
|
// This content element has no displayport data at all
|
2011-03-16 02:20:19 +03:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-21 20:06:02 +04:00
|
|
|
|
if (!aResult) {
|
2014-05-21 20:06:03 +04:00
|
|
|
|
// We have displayport data, but the caller doesn't want the actual
|
|
|
|
|
// rect, so we don't need to actually compute it.
|
2014-05-21 20:06:02 +04:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-03-27 05:46:23 +04:00
|
|
|
|
|
2014-05-21 20:06:02 +04:00
|
|
|
|
if (rectData && marginsData) {
|
|
|
|
|
// choose margins if equal priority
|
|
|
|
|
if (rectData->mPriority > marginsData->mPriority) {
|
|
|
|
|
marginsData = nullptr;
|
2014-03-27 05:46:23 +04:00
|
|
|
|
} else {
|
2014-05-21 20:06:02 +04:00
|
|
|
|
rectData = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-10 21:16:20 +04:00
|
|
|
|
|
2014-05-21 20:06:03 +04:00
|
|
|
|
NS_ASSERTION((rectData == nullptr) != (marginsData == nullptr),
|
|
|
|
|
"Only one of rectData or marginsData should be set!");
|
2014-05-21 20:06:02 +04:00
|
|
|
|
|
2015-03-17 08:59:29 +03:00
|
|
|
|
nsRect result;
|
2014-05-21 20:06:02 +04:00
|
|
|
|
if (rectData) {
|
2015-03-17 08:59:29 +03:00
|
|
|
|
result = GetDisplayPortFromRectData(aContent, rectData, aMultiplier);
|
2014-05-21 20:06:02 +04:00
|
|
|
|
} else {
|
2015-03-17 08:59:29 +03:00
|
|
|
|
result = GetDisplayPortFromMarginsData(aContent, marginsData, aMultiplier);
|
2014-05-21 20:06:02 +04:00
|
|
|
|
}
|
2015-03-17 08:59:29 +03:00
|
|
|
|
|
|
|
|
|
if (!gfxPrefs::LayersTilesEnabled()) {
|
|
|
|
|
// Either we should have gotten a valid rect directly from the displayport
|
|
|
|
|
// base, or we should have computed a valid rect from the margins.
|
2015-03-23 22:34:21 +03:00
|
|
|
|
NS_ASSERTION(result.width <= GetMaxDisplayPortSize(aContent),
|
2015-03-17 08:59:29 +03:00
|
|
|
|
"Displayport must be a valid texture size");
|
2015-03-23 22:34:21 +03:00
|
|
|
|
NS_ASSERTION(result.height <= GetMaxDisplayPortSize(aContent),
|
2015-03-17 08:59:29 +03:00
|
|
|
|
"Displayport must be a valid texture size");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*aResult = result;
|
2011-03-16 02:20:19 +03:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2003-01-05 08:05:17 +03:00
|
|
|
|
|
2014-05-21 20:06:02 +04:00
|
|
|
|
bool
|
|
|
|
|
nsLayoutUtils::GetDisplayPort(nsIContent* aContent, nsRect *aResult)
|
|
|
|
|
{
|
|
|
|
|
if (gfxPrefs::UseLowPrecisionBuffer()) {
|
|
|
|
|
return GetDisplayPortImpl(aContent, aResult, 1.0f / gfxPrefs::LowPrecisionResolution());
|
|
|
|
|
}
|
2014-05-21 20:06:03 +04:00
|
|
|
|
return GetDisplayPortImpl(aContent, aResult, 1.0f);
|
2014-05-21 20:06:02 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-30 08:33:37 +03:00
|
|
|
|
/* static */ bool
|
|
|
|
|
nsLayoutUtils::GetDisplayPortForVisibilityTesting(nsIContent* aContent,
|
|
|
|
|
nsRect* aResult)
|
|
|
|
|
{
|
|
|
|
|
return GetDisplayPortImpl(aContent, aResult, 1.0f);
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-22 05:36:25 +03:00
|
|
|
|
bool
|
2014-04-04 18:13:50 +04:00
|
|
|
|
nsLayoutUtils::SetDisplayPortMargins(nsIContent* aContent,
|
|
|
|
|
nsIPresShell* aPresShell,
|
2014-10-24 23:49:38 +04:00
|
|
|
|
const ScreenMargin& aMargins,
|
2014-04-04 18:13:50 +04:00
|
|
|
|
uint32_t aPriority,
|
|
|
|
|
RepaintMode aRepaintMode)
|
|
|
|
|
{
|
2015-04-19 18:19:14 +03:00
|
|
|
|
MOZ_ASSERT(aContent);
|
2015-04-22 06:01:41 +03:00
|
|
|
|
MOZ_ASSERT(aContent->GetComposedDoc() == aPresShell->GetDocument());
|
2015-04-19 18:19:14 +03:00
|
|
|
|
|
2014-04-04 18:13:50 +04:00
|
|
|
|
DisplayPortMarginsPropertyData* currentData =
|
|
|
|
|
static_cast<DisplayPortMarginsPropertyData*>(aContent->GetProperty(nsGkAtoms::DisplayPortMargins));
|
|
|
|
|
if (currentData && currentData->mPriority > aPriority) {
|
2014-11-22 05:36:25 +03:00
|
|
|
|
return false;
|
2014-04-04 18:13:50 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-07 22:37:56 +03:00
|
|
|
|
if (currentData && currentData->mMargins == aMargins) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-04 18:13:50 +04:00
|
|
|
|
aContent->SetProperty(nsGkAtoms::DisplayPortMargins,
|
|
|
|
|
new DisplayPortMarginsPropertyData(
|
2014-11-13 01:54:29 +03:00
|
|
|
|
aMargins, aPriority),
|
2014-04-04 18:13:50 +04:00
|
|
|
|
nsINode::DeleteProperty<DisplayPortMarginsPropertyData>);
|
|
|
|
|
|
2015-06-04 23:51:10 +03:00
|
|
|
|
if (gfxPrefs::LayoutUseContainersForRootFrames()) {
|
2014-07-24 07:14:02 +04:00
|
|
|
|
nsIFrame* rootScrollFrame = aPresShell->GetRootScrollFrame();
|
2015-06-04 23:51:10 +03:00
|
|
|
|
if (rootScrollFrame &&
|
|
|
|
|
aContent == rootScrollFrame->GetContent() &&
|
|
|
|
|
nsLayoutUtils::UsesAsyncScrolling(rootScrollFrame))
|
|
|
|
|
{
|
2014-07-24 07:14:02 +04:00
|
|
|
|
// We are setting a root displayport for a document.
|
|
|
|
|
// If we have APZ, then set a special flag on the pres shell so
|
|
|
|
|
// that we don't get scrollbars drawn.
|
|
|
|
|
aPresShell->SetIgnoreViewportScrolling(true);
|
|
|
|
|
}
|
2014-04-04 18:13:50 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (aRepaintMode == RepaintMode::Repaint) {
|
|
|
|
|
nsIFrame* rootFrame = aPresShell->FrameManager()->GetRootFrame();
|
|
|
|
|
if (rootFrame) {
|
|
|
|
|
rootFrame->SchedulePaint();
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-11-22 05:36:25 +03:00
|
|
|
|
|
2015-05-30 09:50:53 +03:00
|
|
|
|
// Display port margins changing means that the set of visible images may
|
|
|
|
|
// have drastically changed. Schedule an update.
|
|
|
|
|
aPresShell->ScheduleImageVisibilityUpdate();
|
|
|
|
|
|
2014-11-22 05:36:25 +03:00
|
|
|
|
return true;
|
2014-04-04 18:13:50 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-27 05:46:24 +04:00
|
|
|
|
void
|
|
|
|
|
nsLayoutUtils::SetDisplayPortBase(nsIContent* aContent, const nsRect& aBase)
|
|
|
|
|
{
|
|
|
|
|
aContent->SetProperty(nsGkAtoms::DisplayPortBase, new nsRect(aBase),
|
|
|
|
|
nsINode::DeleteProperty<nsRect>);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-26 09:13:36 +04:00
|
|
|
|
void
|
|
|
|
|
nsLayoutUtils::SetDisplayPortBaseIfNotSet(nsIContent* aContent, const nsRect& aBase)
|
|
|
|
|
{
|
|
|
|
|
if (!aContent->GetProperty(nsGkAtoms::DisplayPortBase)) {
|
|
|
|
|
SetDisplayPortBase(aContent, aBase);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-22 02:34:18 +04:00
|
|
|
|
bool
|
|
|
|
|
nsLayoutUtils::GetCriticalDisplayPort(nsIContent* aContent, nsRect* aResult)
|
|
|
|
|
{
|
2014-05-21 20:06:02 +04:00
|
|
|
|
if (gfxPrefs::UseLowPrecisionBuffer()) {
|
2014-05-21 20:06:03 +04:00
|
|
|
|
return GetDisplayPortImpl(aContent, aResult, 1.0f);
|
2012-11-22 02:34:18 +04:00
|
|
|
|
}
|
2014-05-21 20:06:02 +04:00
|
|
|
|
return false;
|
2012-11-22 02:34:18 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-25 02:20:39 +04:00
|
|
|
|
nsContainerFrame*
|
|
|
|
|
nsLayoutUtils::LastContinuationWithChild(nsContainerFrame* aFrame)
|
2008-01-27 11:13:19 +03:00
|
|
|
|
{
|
|
|
|
|
NS_PRECONDITION(aFrame, "NULL frame pointer");
|
2014-05-25 02:20:39 +04:00
|
|
|
|
nsIFrame* f = aFrame->LastContinuation();
|
|
|
|
|
while (!f->GetFirstPrincipalChild() && f->GetPrevContinuation()) {
|
|
|
|
|
f = f->GetPrevContinuation();
|
2008-01-27 11:13:19 +03:00
|
|
|
|
}
|
2014-05-25 02:20:39 +04:00
|
|
|
|
return static_cast<nsContainerFrame*>(f);
|
2008-01-27 11:13:19 +03:00
|
|
|
|
}
|
|
|
|
|
|
2009-12-24 08:20:41 +03:00
|
|
|
|
//static
|
2013-10-01 01:26:04 +04:00
|
|
|
|
FrameChildListID
|
2009-12-24 08:20:41 +03:00
|
|
|
|
nsLayoutUtils::GetChildListNameFor(nsIFrame* aChildFrame)
|
|
|
|
|
{
|
2011-08-25 00:54:30 +04:00
|
|
|
|
nsIFrame::ChildListID id = nsIFrame::kPrincipalList;
|
2009-12-24 08:20:41 +03:00
|
|
|
|
|
|
|
|
|
if (aChildFrame->GetStateBits() & NS_FRAME_IS_OVERFLOW_CONTAINER) {
|
|
|
|
|
nsIFrame* pif = aChildFrame->GetPrevInFlow();
|
|
|
|
|
if (pif->GetParent() == aChildFrame->GetParent()) {
|
2011-08-25 00:54:30 +04:00
|
|
|
|
id = nsIFrame::kExcessOverflowContainersList;
|
2009-12-24 08:20:41 +03:00
|
|
|
|
}
|
|
|
|
|
else {
|
2011-08-25 00:54:30 +04:00
|
|
|
|
id = nsIFrame::kOverflowContainersList;
|
2009-12-24 08:20:41 +03: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
|
2013-02-17 01:51:02 +04:00
|
|
|
|
const nsStyleDisplay* disp = aChildFrame->StyleDisplay();
|
2009-12-24 08:20:41 +03:00
|
|
|
|
|
|
|
|
|
if (NS_STYLE_POSITION_ABSOLUTE == disp->mPosition) {
|
2011-08-25 00:54:30 +04:00
|
|
|
|
id = nsIFrame::kAbsoluteList;
|
2009-12-24 08:20:41 +03:00
|
|
|
|
} else if (NS_STYLE_POSITION_FIXED == disp->mPosition) {
|
|
|
|
|
if (nsLayoutUtils::IsReallyFixedPos(aChildFrame)) {
|
2011-08-25 00:54:30 +04:00
|
|
|
|
id = nsIFrame::kFixedList;
|
2009-12-24 08:20:41 +03:00
|
|
|
|
} else {
|
2011-08-25 00:54:30 +04:00
|
|
|
|
id = nsIFrame::kAbsoluteList;
|
2009-12-24 08:20:41 +03: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
|
|
|
|
|
|
2013-11-04 20:22:20 +04:00
|
|
|
|
id = nsIFrame::kPopupList;
|
2009-12-24 08:20:41 +03:00
|
|
|
|
#endif // MOZ_XUL
|
|
|
|
|
} else {
|
2013-03-16 02:32:35 +04:00
|
|
|
|
NS_ASSERTION(aChildFrame->IsFloating(), "not a floated frame");
|
2011-08-25 00:54:30 +04:00
|
|
|
|
id = nsIFrame::kFloatList;
|
2009-12-24 08:20:41 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
nsIAtom* childType = aChildFrame->GetType();
|
|
|
|
|
if (nsGkAtoms::menuPopupFrame == childType) {
|
|
|
|
|
nsIFrame* parent = aChildFrame->GetParent();
|
2013-11-04 20:22:20 +04:00
|
|
|
|
MOZ_ASSERT(parent, "nsMenuPopupFrame can't be the root frame");
|
|
|
|
|
if (parent) {
|
|
|
|
|
if (parent->GetType() == nsGkAtoms::popupSetFrame) {
|
|
|
|
|
id = nsIFrame::kPopupList;
|
|
|
|
|
} else {
|
|
|
|
|
nsIFrame* firstPopup = parent->GetFirstChild(nsIFrame::kPopupList);
|
|
|
|
|
MOZ_ASSERT(!firstPopup || !firstPopup->GetNextSibling(),
|
|
|
|
|
"We assume popupList only has one child, but it has more.");
|
|
|
|
|
id = firstPopup == aChildFrame
|
|
|
|
|
? nsIFrame::kPopupList
|
|
|
|
|
: nsIFrame::kPrincipalList;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
id = nsIFrame::kPrincipalList;
|
|
|
|
|
}
|
2009-12-24 08:20:41 +03:00
|
|
|
|
} else if (nsGkAtoms::tableColGroupFrame == childType) {
|
2011-08-25 00:54:30 +04:00
|
|
|
|
id = nsIFrame::kColGroupList;
|
2014-12-26 10:21:32 +03:00
|
|
|
|
} else if (aChildFrame->IsTableCaption()) {
|
2011-08-25 00:54:30 +04:00
|
|
|
|
id = nsIFrame::kCaptionList;
|
2009-12-24 08:20:41 +03:00
|
|
|
|
} else {
|
2011-08-25 00:54:30 +04:00
|
|
|
|
id = nsIFrame::kPrincipalList;
|
2009-12-24 08:20:41 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-25 23:59:42 +04:00
|
|
|
|
#ifdef DEBUG
|
2009-12-24 08:20:41 +03:00
|
|
|
|
// Verify that the frame is actually in that child list or in the
|
|
|
|
|
// corresponding overflow list.
|
2014-05-25 02:20:39 +04:00
|
|
|
|
nsContainerFrame* parent = aChildFrame->GetParent();
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool found = parent->GetChildList(id).ContainsFrame(aChildFrame);
|
2009-12-24 08:20:41 +03:00
|
|
|
|
if (!found) {
|
|
|
|
|
if (!(aChildFrame->GetStateBits() & NS_FRAME_OUT_OF_FLOW)) {
|
2011-08-25 00:54:30 +04:00
|
|
|
|
found = parent->GetChildList(nsIFrame::kOverflowList)
|
2009-12-24 08:20:41 +03:00
|
|
|
|
.ContainsFrame(aChildFrame);
|
|
|
|
|
}
|
2012-08-02 15:38:49 +04:00
|
|
|
|
else if (aChildFrame->IsFloating()) {
|
2011-08-25 00:54:30 +04:00
|
|
|
|
found = parent->GetChildList(nsIFrame::kOverflowOutOfFlowList)
|
2009-12-24 08:20:41 +03:00
|
|
|
|
.ContainsFrame(aChildFrame);
|
2013-03-16 02:32:35 +04:00
|
|
|
|
if (!found) {
|
|
|
|
|
found = parent->GetChildList(nsIFrame::kPushedFloatsList)
|
|
|
|
|
.ContainsFrame(aChildFrame);
|
|
|
|
|
}
|
2009-12-24 08:20:41 +03:00
|
|
|
|
}
|
2011-08-25 00:54:30 +04:00
|
|
|
|
// else it's positioned and should have been on the 'id' child list.
|
2009-12-24 08:20:41 +03:00
|
|
|
|
NS_POSTCONDITION(found, "not in child list");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-08-25 00:54:30 +04:00
|
|
|
|
return id;
|
2009-12-24 08:20:41 +03:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-20 21:24:10 +03:00
|
|
|
|
/*static*/ nsIFrame*
|
|
|
|
|
nsLayoutUtils::GetBeforeFrameForContent(nsIFrame* aFrame,
|
|
|
|
|
nsIContent* aContent)
|
2003-01-05 08:05:17 +03:00
|
|
|
|
{
|
2015-01-12 02:43:11 +03:00
|
|
|
|
// We need to call GetGenConPseudos() on the first continuation/ib-split.
|
|
|
|
|
// Find it, for symmetry with GetAfterFrameForContent.
|
|
|
|
|
nsContainerFrame* genConParentFrame =
|
|
|
|
|
FirstContinuationOrIBSplitSibling(aFrame)->GetContentInsertionFrame();
|
2014-11-20 21:24:10 +03:00
|
|
|
|
if (!genConParentFrame) {
|
2014-05-25 02:20:39 +04:00
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2014-11-20 21:24:10 +03:00
|
|
|
|
nsTArray<nsIContent*>* prop = genConParentFrame->GetGenConPseudos();
|
|
|
|
|
if (prop) {
|
|
|
|
|
const nsTArray<nsIContent*>& pseudos(*prop);
|
|
|
|
|
for (uint32_t i = 0; i < pseudos.Length(); ++i) {
|
|
|
|
|
if (pseudos[i]->GetParent() == aContent &&
|
2015-03-03 14:09:00 +03:00
|
|
|
|
pseudos[i]->NodeInfo()->NameAtom() == nsGkAtoms::mozgeneratedcontentbefore) {
|
2014-11-20 21:24:10 +03:00
|
|
|
|
return pseudos[i]->GetPrimaryFrame();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// If the first child frame is a pseudo-frame, then try that.
|
|
|
|
|
// Note that the frame we create for the generated content is also a
|
|
|
|
|
// pseudo-frame and so don't drill down in that case.
|
|
|
|
|
nsIFrame* childFrame = genConParentFrame->GetFirstPrincipalChild();
|
|
|
|
|
if (childFrame &&
|
|
|
|
|
childFrame->IsPseudoFrame(aContent) &&
|
|
|
|
|
!childFrame->IsGeneratedContentFrame()) {
|
|
|
|
|
return GetBeforeFrameForContent(childFrame, aContent);
|
2003-01-05 08:05:17 +03:00
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
|
return nullptr;
|
2003-01-05 08:05:17 +03:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-20 21:24:10 +03:00
|
|
|
|
/*static*/ nsIFrame*
|
|
|
|
|
nsLayoutUtils::GetBeforeFrame(nsIFrame* aFrame)
|
2003-01-05 08:05:17 +03:00
|
|
|
|
{
|
2014-11-20 21:24:10 +03:00
|
|
|
|
return GetBeforeFrameForContent(aFrame, aFrame->GetContent());
|
|
|
|
|
}
|
2003-01-05 08:05:17 +03:00
|
|
|
|
|
2014-11-20 21:24:10 +03:00
|
|
|
|
/*static*/ nsIFrame*
|
|
|
|
|
nsLayoutUtils::GetAfterFrameForContent(nsIFrame* aFrame,
|
|
|
|
|
nsIContent* aContent)
|
|
|
|
|
{
|
2015-01-12 02:43:11 +03:00
|
|
|
|
// We need to call GetGenConPseudos() on the first continuation,
|
|
|
|
|
// but callers are likely to pass the last.
|
|
|
|
|
nsContainerFrame* genConParentFrame =
|
|
|
|
|
FirstContinuationOrIBSplitSibling(aFrame)->GetContentInsertionFrame();
|
2014-11-20 21:24:10 +03:00
|
|
|
|
if (!genConParentFrame) {
|
2014-05-25 02:20:39 +04:00
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2014-11-20 21:24:10 +03:00
|
|
|
|
nsTArray<nsIContent*>* prop = genConParentFrame->GetGenConPseudos();
|
|
|
|
|
if (prop) {
|
|
|
|
|
const nsTArray<nsIContent*>& pseudos(*prop);
|
|
|
|
|
for (uint32_t i = 0; i < pseudos.Length(); ++i) {
|
|
|
|
|
if (pseudos[i]->GetParent() == aContent &&
|
2015-03-03 14:09:00 +03:00
|
|
|
|
pseudos[i]->NodeInfo()->NameAtom() == nsGkAtoms::mozgeneratedcontentafter) {
|
2014-11-20 21:24:10 +03:00
|
|
|
|
return pseudos[i]->GetPrimaryFrame();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// If the last child frame is a pseudo-frame, then try that.
|
|
|
|
|
// Note that the frame we create for the generated content is also a
|
|
|
|
|
// pseudo-frame and so don't drill down in that case.
|
2015-01-12 02:43:11 +03:00
|
|
|
|
genConParentFrame = aFrame->GetContentInsertionFrame();
|
|
|
|
|
if (!genConParentFrame) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2014-11-20 21:24:10 +03:00
|
|
|
|
nsIFrame* lastParentContinuation =
|
2015-01-12 02:43:11 +03:00
|
|
|
|
LastContinuationWithChild(static_cast<nsContainerFrame*>(
|
|
|
|
|
LastContinuationOrIBSplitSibling(genConParentFrame)));
|
2014-11-20 21:24:10 +03:00
|
|
|
|
nsIFrame* childFrame =
|
|
|
|
|
lastParentContinuation->GetLastChild(nsIFrame::kPrincipalList);
|
|
|
|
|
if (childFrame &&
|
|
|
|
|
childFrame->IsPseudoFrame(aContent) &&
|
|
|
|
|
!childFrame->IsGeneratedContentFrame()) {
|
|
|
|
|
return GetAfterFrameForContent(childFrame->FirstContinuation(), aContent);
|
2003-01-05 08:05:17 +03:00
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
|
return nullptr;
|
2003-01-05 08:05:17 +03:00
|
|
|
|
}
|
2003-02-23 05:49:22 +03:00
|
|
|
|
|
2014-11-20 21:24:10 +03:00
|
|
|
|
/*static*/ nsIFrame*
|
|
|
|
|
nsLayoutUtils::GetAfterFrame(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
return GetAfterFrameForContent(aFrame, aFrame->GetContent());
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-22 03:06:40 +04:00
|
|
|
|
// static
|
2003-02-23 05:49:22 +03:00
|
|
|
|
nsIFrame*
|
2007-07-04 05:13:07 +04:00
|
|
|
|
nsLayoutUtils::GetClosestFrameOfType(nsIFrame* aFrame, nsIAtom* aFrameType)
|
2003-02-23 05:49:22 +03:00
|
|
|
|
{
|
2003-07-02 14:30:00 +04:00
|
|
|
|
for (nsIFrame* frame = aFrame; frame; frame = frame->GetParent()) {
|
2007-07-04 05:13:07 +04:00
|
|
|
|
if (frame->GetType() == aFrameType) {
|
2003-02-23 05:49:22 +03:00
|
|
|
|
return frame;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
|
return nullptr;
|
2003-02-23 05:49:22 +03:00
|
|
|
|
}
|
2003-04-22 03:06:40 +04:00
|
|
|
|
|
2009-12-01 20:21:00 +03:00
|
|
|
|
// static
|
|
|
|
|
nsIFrame*
|
|
|
|
|
nsLayoutUtils::GetStyleFrame(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
if (aFrame->GetType() == nsGkAtoms::tableOuterFrame) {
|
2011-08-25 00:54:30 +04:00
|
|
|
|
nsIFrame* inner = aFrame->GetFirstPrincipalChild();
|
2009-12-01 20:21:00 +03:00
|
|
|
|
NS_ASSERTION(inner, "Outer table must have an inner");
|
|
|
|
|
return inner;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return aFrame;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-25 09:32:10 +04:00
|
|
|
|
nsIFrame*
|
|
|
|
|
nsLayoutUtils::GetStyleFrame(const nsIContent* aContent)
|
|
|
|
|
{
|
|
|
|
|
nsIFrame *frame = aContent->GetPrimaryFrame();
|
|
|
|
|
if (!frame) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nsLayoutUtils::GetStyleFrame(frame);
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-13 17:35:46 +04:00
|
|
|
|
nsIFrame*
|
|
|
|
|
nsLayoutUtils::GetFloatFromPlaceholder(nsIFrame* aFrame) {
|
2009-11-17 00:00:07 +03:00
|
|
|
|
NS_ASSERTION(nsGkAtoms::placeholderFrame == aFrame->GetType(),
|
|
|
|
|
"Must have a placeholder here");
|
2009-11-17 00:00:07 +03:00
|
|
|
|
if (aFrame->GetStateBits() & PLACEHOLDER_FOR_FLOAT) {
|
|
|
|
|
nsIFrame *outOfFlowFrame =
|
|
|
|
|
nsPlaceholderFrame::GetRealFrameForPlaceholder(aFrame);
|
2012-08-02 15:38:49 +04:00
|
|
|
|
NS_ASSERTION(outOfFlowFrame->IsFloating(),
|
2009-11-17 00:00:07 +03:00
|
|
|
|
"How did that happen?");
|
2004-09-13 17:35:46 +04:00
|
|
|
|
return outOfFlowFrame;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
|
return nullptr;
|
2004-09-13 17:35:46 +04:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-22 03:06:40 +04:00
|
|
|
|
// static
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool
|
2003-04-22 03:06:40 +04: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 18:59:28 +04:00
|
|
|
|
return false;
|
2003-04-22 03:06:40 +04:00
|
|
|
|
}
|
2008-08-18 05:16:42 +04: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 18:59:28 +04:00
|
|
|
|
return false;
|
2008-08-18 05:16:42 +04:00
|
|
|
|
}
|
2010-04-27 20:15:01 +04:00
|
|
|
|
|
2008-08-18 05:16:42 +04:00
|
|
|
|
if (aContent && parent->GetContent() != aContent) {
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2003-04-22 03:06:40 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-03 14:09:00 +03:00
|
|
|
|
return (aFrame->GetContent()->NodeInfo()->NameAtom() == nsGkAtoms::mozgeneratedcontentbefore) ==
|
2008-08-18 05:16:42 +04:00
|
|
|
|
(aPseudoElement == nsCSSPseudoElements::before);
|
2003-04-22 03:06:40 +04:00
|
|
|
|
}
|
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
|
// static
|
|
|
|
|
nsIFrame*
|
2008-09-04 01:35:52 +04:00
|
|
|
|
nsLayoutUtils::GetCrossDocParentFrame(const nsIFrame* aFrame,
|
|
|
|
|
nsPoint* aExtraOffset)
|
2006-01-26 05:29:17 +03:00
|
|
|
|
{
|
|
|
|
|
nsIFrame* p = aFrame->GetParent();
|
|
|
|
|
if (p)
|
|
|
|
|
return p;
|
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
|
nsView* v = aFrame->GetView();
|
2006-01-26 05:29:17 +03:00
|
|
|
|
if (!v)
|
2012-07-30 18:20:58 +04:00
|
|
|
|
return nullptr;
|
2006-01-26 05:29:17 +03:00
|
|
|
|
v = v->GetParent(); // anonymous inner view
|
|
|
|
|
if (!v)
|
2012-07-30 18:20:58 +04:00
|
|
|
|
return nullptr;
|
2008-09-04 01:35:52 +04:00
|
|
|
|
if (aExtraOffset) {
|
|
|
|
|
*aExtraOffset += v->GetPosition();
|
|
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
|
v = v->GetParent(); // subdocumentframe's view
|
2012-07-30 18:20:58 +04:00
|
|
|
|
return v ? v->GetFrame() : nullptr;
|
2006-01-26 05:29:17 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// static
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool
|
2006-01-26 05:29:17 +03:00
|
|
|
|
nsLayoutUtils::IsProperAncestorFrameCrossDoc(nsIFrame* aAncestorFrame, nsIFrame* aFrame,
|
|
|
|
|
nsIFrame* aCommonAncestor)
|
|
|
|
|
{
|
2012-08-20 02:25:49 +04:00
|
|
|
|
if (aFrame == aAncestorFrame)
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2012-08-20 02:25:49 +04:00
|
|
|
|
return IsAncestorFrameCrossDoc(aAncestorFrame, aFrame, aCommonAncestor);
|
2006-01-26 05:29:17 +03:00
|
|
|
|
}
|
|
|
|
|
|
2009-07-22 04:44:56 +04:00
|
|
|
|
// static
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool
|
2012-09-13 04:32:53 +04:00
|
|
|
|
nsLayoutUtils::IsAncestorFrameCrossDoc(const nsIFrame* aAncestorFrame, const nsIFrame* aFrame,
|
|
|
|
|
const nsIFrame* aCommonAncestor)
|
2009-07-22 04:44:56 +04:00
|
|
|
|
{
|
2012-09-13 04:32:53 +04:00
|
|
|
|
for (const nsIFrame* f = aFrame; f != aCommonAncestor;
|
2012-08-20 02:25:49 +04:00
|
|
|
|
f = GetCrossDocParentFrame(f)) {
|
|
|
|
|
if (f == aAncestorFrame)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return aCommonAncestor == aAncestorFrame;
|
2009-07-22 04:44:56 +04:00
|
|
|
|
}
|
|
|
|
|
|
2003-10-15 04:49:03 +04:00
|
|
|
|
// static
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool
|
2003-10-15 04:49:03 +04:00
|
|
|
|
nsLayoutUtils::IsProperAncestorFrame(nsIFrame* aAncestorFrame, nsIFrame* aFrame,
|
|
|
|
|
nsIFrame* aCommonAncestor)
|
|
|
|
|
{
|
2012-08-20 02:25:49 +04:00
|
|
|
|
if (aFrame == aAncestorFrame)
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2012-08-20 02:25:49 +04:00
|
|
|
|
for (nsIFrame* f = aFrame; f != aCommonAncestor; f = f->GetParent()) {
|
|
|
|
|
if (f == aAncestorFrame)
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true;
|
2003-10-15 04:49:03 +04:00
|
|
|
|
}
|
2012-08-20 02:25:49 +04:00
|
|
|
|
return aCommonAncestor == aAncestorFrame;
|
2003-10-15 04:49:03 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// static
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t
|
2004-04-13 01:53:22 +04:00
|
|
|
|
nsLayoutUtils::DoCompareTreePosition(nsIContent* aContent1,
|
|
|
|
|
nsIContent* aContent2,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t aIf1Ancestor,
|
|
|
|
|
int32_t aIf2Ancestor,
|
2009-09-18 22:52:27 +04:00
|
|
|
|
const nsIContent* aCommonAncestor)
|
2004-04-13 01:53:22 +04:00
|
|
|
|
{
|
2003-10-15 04:49:03 +04:00
|
|
|
|
NS_PRECONDITION(aContent1, "aContent1 must not be null");
|
|
|
|
|
NS_PRECONDITION(aContent2, "aContent2 must not be null");
|
|
|
|
|
|
2007-11-11 23:35:30 +03:00
|
|
|
|
nsAutoTArray<nsINode*, 32> content1Ancestors;
|
2006-05-16 19:50:47 +04:00
|
|
|
|
nsINode* c1;
|
2012-10-09 16:31:24 +04:00
|
|
|
|
for (c1 = aContent1; c1 && c1 != aCommonAncestor; c1 = c1->GetParentNode()) {
|
2003-10-17 18:10:02 +04:00
|
|
|
|
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 18:20:58 +04:00
|
|
|
|
aCommonAncestor = nullptr;
|
2003-10-17 18:10:02 +04:00
|
|
|
|
}
|
2003-10-15 04:49:03 +04:00
|
|
|
|
|
2007-11-11 23:35:30 +03:00
|
|
|
|
nsAutoTArray<nsINode*, 32> content2Ancestors;
|
2006-05-16 19:50:47 +04:00
|
|
|
|
nsINode* c2;
|
2012-10-09 16:31:24 +04:00
|
|
|
|
for (c2 = aContent2; c2 && c2 != aCommonAncestor; c2 = c2->GetParentNode()) {
|
2003-10-17 18:10:02 +04:00
|
|
|
|
content2Ancestors.AppendElement(c2);
|
2003-10-15 04:49:03 +04:00
|
|
|
|
}
|
2003-10-17 18:10:02 +04:00
|
|
|
|
if (!c2 && aCommonAncestor) {
|
|
|
|
|
// So, it turns out aCommonAncestor was not an ancestor of c2.
|
|
|
|
|
// We need to retry with no common ancestor hint.
|
2004-04-13 01:53:22 +04:00
|
|
|
|
return DoCompareTreePosition(aContent1, aContent2,
|
2012-07-30 18:20:58 +04:00
|
|
|
|
aIf1Ancestor, aIf2Ancestor, nullptr);
|
2003-10-15 04:49:03 +04:00
|
|
|
|
}
|
2010-04-27 20:15:01 +04:00
|
|
|
|
|
2007-11-11 23:35:30 +03:00
|
|
|
|
int last1 = content1Ancestors.Length() - 1;
|
|
|
|
|
int last2 = content2Ancestors.Length() - 1;
|
2012-07-30 18:20:58 +04:00
|
|
|
|
nsINode* content1Ancestor = nullptr;
|
|
|
|
|
nsINode* content2Ancestor = nullptr;
|
2003-10-15 04:49:03 +04:00
|
|
|
|
while (last1 >= 0 && last2 >= 0
|
2007-11-11 23:35:30 +03:00
|
|
|
|
&& ((content1Ancestor = content1Ancestors.ElementAt(last1)) ==
|
|
|
|
|
(content2Ancestor = content2Ancestors.ElementAt(last2)))) {
|
2003-10-15 04:49:03 +04:00
|
|
|
|
last1--;
|
|
|
|
|
last2--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (last1 < 0) {
|
|
|
|
|
if (last2 < 0) {
|
|
|
|
|
NS_ASSERTION(aContent1 == aContent2, "internal error?");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2006-05-16 19:50:47 +04:00
|
|
|
|
// aContent1 is an ancestor of aContent2
|
|
|
|
|
return aIf1Ancestor;
|
2003-10-15 04:49:03 +04:00
|
|
|
|
}
|
2006-05-16 19:50:47 +04:00
|
|
|
|
|
|
|
|
|
if (last2 < 0) {
|
|
|
|
|
// aContent2 is an ancestor of aContent1
|
|
|
|
|
return aIf2Ancestor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// content1Ancestor != content2Ancestor, so they must be siblings with the same parent
|
2012-10-09 16:31:24 +04:00
|
|
|
|
nsINode* parent = content1Ancestor->GetParentNode();
|
2010-10-13 14:52:45 +04:00
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
// TODO: remove the uglyness, see bug 598468.
|
|
|
|
|
NS_ASSERTION(gPreventAssertInCompareTreePosition || parent,
|
|
|
|
|
"no common ancestor at all???");
|
|
|
|
|
#endif // DEBUG
|
2006-05-16 19:50:47 +04:00
|
|
|
|
if (!parent) { // different documents??
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t index1 = parent->IndexOf(content1Ancestor);
|
|
|
|
|
int32_t index2 = parent->IndexOf(content2Ancestor);
|
2006-05-16 19:50:47 +04:00
|
|
|
|
if (index1 < 0 || index2 < 0) {
|
|
|
|
|
// one of them must be anonymous; we can't determine the order
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return index1 - index2;
|
2003-10-15 04:49:03 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-22 16:06:01 +04:00
|
|
|
|
// static
|
|
|
|
|
nsIFrame*
|
|
|
|
|
nsLayoutUtils::FillAncestors(nsIFrame* aFrame,
|
|
|
|
|
nsIFrame* aStopAtAncestor,
|
|
|
|
|
nsTArray<nsIFrame*>* aAncestors)
|
2007-01-18 01:48:24 +03:00
|
|
|
|
{
|
|
|
|
|
while (aFrame && aFrame != aStopAtAncestor) {
|
|
|
|
|
aAncestors->AppendElement(aFrame);
|
2012-06-11 03:44:50 +04:00
|
|
|
|
aFrame = nsLayoutUtils::GetParentOrPlaceholderFor(aFrame);
|
2007-01-18 01:48:24 +03:00
|
|
|
|
}
|
|
|
|
|
return aFrame;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Return true if aFrame1 is after aFrame2
|
2011-09-29 10:19:26 +04:00
|
|
|
|
static bool IsFrameAfter(nsIFrame* aFrame1, nsIFrame* aFrame2)
|
2007-01-18 01:48:24 +03:00
|
|
|
|
{
|
|
|
|
|
nsIFrame* f = aFrame2;
|
|
|
|
|
do {
|
|
|
|
|
f = f->GetNextSibling();
|
|
|
|
|
if (f == aFrame1)
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true;
|
2007-01-18 01:48:24 +03:00
|
|
|
|
} while (f);
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2007-01-18 01:48:24 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// static
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t
|
2007-01-18 01:48:24 +03:00
|
|
|
|
nsLayoutUtils::DoCompareTreePosition(nsIFrame* aFrame1,
|
|
|
|
|
nsIFrame* aFrame2,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t aIf1Ancestor,
|
|
|
|
|
int32_t aIf2Ancestor,
|
2007-01-18 01:48:24 +03:00
|
|
|
|
nsIFrame* aCommonAncestor)
|
|
|
|
|
{
|
|
|
|
|
NS_PRECONDITION(aFrame1, "aFrame1 must not be null");
|
|
|
|
|
NS_PRECONDITION(aFrame2, "aFrame2 must not be null");
|
|
|
|
|
|
2013-10-22 16:06:01 +04:00
|
|
|
|
nsAutoTArray<nsIFrame*,20> frame2Ancestors;
|
|
|
|
|
nsIFrame* nonCommonAncestor =
|
|
|
|
|
FillAncestors(aFrame2, aCommonAncestor, &frame2Ancestors);
|
|
|
|
|
|
|
|
|
|
return DoCompareTreePosition(aFrame1, aFrame2, frame2Ancestors,
|
|
|
|
|
aIf1Ancestor, aIf2Ancestor,
|
|
|
|
|
nonCommonAncestor ? aCommonAncestor : nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// static
|
|
|
|
|
int32_t
|
|
|
|
|
nsLayoutUtils::DoCompareTreePosition(nsIFrame* aFrame1,
|
|
|
|
|
nsIFrame* aFrame2,
|
|
|
|
|
nsTArray<nsIFrame*>& aFrame2Ancestors,
|
|
|
|
|
int32_t aIf1Ancestor,
|
|
|
|
|
int32_t aIf2Ancestor,
|
|
|
|
|
nsIFrame* aCommonAncestor)
|
|
|
|
|
{
|
|
|
|
|
NS_PRECONDITION(aFrame1, "aFrame1 must not be null");
|
|
|
|
|
NS_PRECONDITION(aFrame2, "aFrame2 must not be null");
|
|
|
|
|
|
2007-03-31 01:11:41 +04:00
|
|
|
|
nsPresContext* presContext = aFrame1->PresContext();
|
|
|
|
|
if (presContext != aFrame2->PresContext()) {
|
2007-01-18 01:48:24 +03:00
|
|
|
|
NS_ERROR("no common ancestor at all, different documents");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsAutoTArray<nsIFrame*,20> frame1Ancestors;
|
2013-10-22 16:06:01 +04:00
|
|
|
|
if (aCommonAncestor &&
|
|
|
|
|
!FillAncestors(aFrame1, aCommonAncestor, &frame1Ancestors)) {
|
2007-01-18 01:48:24 +03:00
|
|
|
|
// We reached the root of the frame tree ... if aCommonAncestor was set,
|
|
|
|
|
// it is wrong
|
|
|
|
|
return DoCompareTreePosition(aFrame1, aFrame2,
|
2012-07-30 18:20:58 +04:00
|
|
|
|
aIf1Ancestor, aIf2Ancestor, nullptr);
|
2007-01-18 01:48:24 +03:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t last1 = int32_t(frame1Ancestors.Length()) - 1;
|
2013-10-22 16:06:01 +04:00
|
|
|
|
int32_t last2 = int32_t(aFrame2Ancestors.Length()) - 1;
|
2007-01-18 01:48:24 +03:00
|
|
|
|
while (last1 >= 0 && last2 >= 0 &&
|
2013-10-22 16:06:01 +04:00
|
|
|
|
frame1Ancestors[last1] == aFrame2Ancestors[last2]) {
|
2007-01-18 01:48:24 +03:00
|
|
|
|
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];
|
2013-10-22 16:06:01 +04:00
|
|
|
|
nsIFrame* ancestor2 = aFrame2Ancestors[last2];
|
2007-01-18 01:48:24 +03:00
|
|
|
|
// 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;
|
|
|
|
|
}
|
|
|
|
|
|
2003-10-15 04:49:03 +04:00
|
|
|
|
// static
|
|
|
|
|
nsIFrame* nsLayoutUtils::GetLastSibling(nsIFrame* aFrame) {
|
|
|
|
|
if (!aFrame) {
|
2012-07-30 18:20:58 +04:00
|
|
|
|
return nullptr;
|
2003-10-15 04:49:03 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIFrame* next;
|
2012-07-30 18:20:58 +04:00
|
|
|
|
while ((next = aFrame->GetNextSibling()) != nullptr) {
|
2003-10-15 04:49:03 +04:00
|
|
|
|
aFrame = next;
|
|
|
|
|
}
|
|
|
|
|
return aFrame;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// static
|
2013-01-03 17:23:11 +04:00
|
|
|
|
nsView*
|
|
|
|
|
nsLayoutUtils::FindSiblingViewFor(nsView* aParentView, nsIFrame* aFrame) {
|
2011-11-21 21:53:20 +04:00
|
|
|
|
nsIFrame* parentViewFrame = aParentView->GetFrame();
|
2012-07-30 18:20:58 +04:00
|
|
|
|
nsIContent* parentViewContent = parentViewFrame ? parentViewFrame->GetContent() : nullptr;
|
2013-01-03 17:23:11 +04:00
|
|
|
|
for (nsView* insertBefore = aParentView->GetFirstChild(); insertBefore;
|
2003-10-15 04:49:03 +04:00
|
|
|
|
insertBefore = insertBefore->GetNextSibling()) {
|
2011-11-21 21:53:20 +04:00
|
|
|
|
nsIFrame* f = insertBefore->GetFrame();
|
2003-10-15 04:49:03 +04:00
|
|
|
|
if (!f) {
|
|
|
|
|
// this view could be some anonymous view attached to a meaningful parent
|
2013-01-03 17:23:11 +04:00
|
|
|
|
for (nsView* searchView = insertBefore->GetParent(); searchView;
|
2003-10-15 04:49:03 +04:00
|
|
|
|
searchView = searchView->GetParent()) {
|
2011-11-21 21:53:20 +04:00
|
|
|
|
f = searchView->GetFrame();
|
2003-10-15 04:49:03 +04:00
|
|
|
|
if (f) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
NS_ASSERTION(f, "Can't find a frame anywhere!");
|
|
|
|
|
}
|
2005-03-24 04:15:07 +03:00
|
|
|
|
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
|
2003-10-15 04:49:03 +04:00
|
|
|
|
return insertBefore;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
|
return nullptr;
|
2003-10-15 04:49:03 +04:00
|
|
|
|
}
|
2004-08-06 19:55:17 +04:00
|
|
|
|
|
2004-11-03 05:52:16 +03:00
|
|
|
|
//static
|
|
|
|
|
nsIScrollableFrame*
|
2012-08-17 03:40:10 +04:00
|
|
|
|
nsLayoutUtils::GetScrollableFrameFor(const nsIFrame *aScrolledFrame)
|
2004-11-03 05:52:16 +03:00
|
|
|
|
{
|
|
|
|
|
nsIFrame *frame = aScrolledFrame->GetParent();
|
2009-01-12 22:20:59 +03:00
|
|
|
|
nsIScrollableFrame *sf = do_QueryFrame(frame);
|
2014-06-23 08:21:42 +04:00
|
|
|
|
return (sf && sf->GetScrolledFrame() == aScrolledFrame) ? sf : nullptr;
|
2004-11-03 05:52:16 +03:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-27 10:02:03 +04:00
|
|
|
|
/* static */ void
|
|
|
|
|
nsLayoutUtils::SetFixedPositionLayerData(Layer* aLayer,
|
|
|
|
|
const nsIFrame* aViewportFrame,
|
2013-12-17 15:30:21 +04:00
|
|
|
|
const nsRect& aAnchorRect,
|
2013-09-27 10:02:03 +04:00
|
|
|
|
const nsIFrame* aFixedPosFrame,
|
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
|
const ContainerLayerParameters& aContainerParameters) {
|
|
|
|
|
// Find out the rect of the viewport frame relative to the reference frame.
|
|
|
|
|
// This, in conjunction with the container scale, will correspond to the
|
|
|
|
|
// coordinate-space of the built layer.
|
|
|
|
|
float factor = aPresContext->AppUnitsPerDevPixel();
|
2013-12-17 15:30:21 +04:00
|
|
|
|
Rect anchorRect(NSAppUnitsToFloatPixels(aAnchorRect.x, factor) *
|
|
|
|
|
aContainerParameters.mXScale,
|
|
|
|
|
NSAppUnitsToFloatPixels(aAnchorRect.y, factor) *
|
|
|
|
|
aContainerParameters.mYScale,
|
|
|
|
|
NSAppUnitsToFloatPixels(aAnchorRect.width, factor) *
|
|
|
|
|
aContainerParameters.mXScale,
|
|
|
|
|
NSAppUnitsToFloatPixels(aAnchorRect.height, factor) *
|
|
|
|
|
aContainerParameters.mYScale);
|
|
|
|
|
// Need to transform anchorRect from the container layer's coordinate system
|
|
|
|
|
// into aLayer's coordinate system.
|
|
|
|
|
Matrix transform2d;
|
|
|
|
|
if (aLayer->GetTransform().Is2D(&transform2d)) {
|
|
|
|
|
transform2d.Invert();
|
|
|
|
|
anchorRect = transform2d.TransformBounds(anchorRect);
|
|
|
|
|
} else {
|
|
|
|
|
NS_ERROR("3D transform found between fixedpos content and its viewport (should never happen)");
|
|
|
|
|
anchorRect = Rect(0,0,0,0);
|
|
|
|
|
}
|
2013-09-27 10:02:03 +04:00
|
|
|
|
|
|
|
|
|
// Work out the anchor point for this fixed position layer. We assume that
|
|
|
|
|
// any positioning set (left/top/right/bottom) indicates that the
|
|
|
|
|
// corresponding side of its container should be the anchor point,
|
|
|
|
|
// defaulting to top-left.
|
2013-12-17 15:30:21 +04:00
|
|
|
|
LayerPoint anchor(anchorRect.x, anchorRect.y);
|
2013-09-27 10:02:03 +04:00
|
|
|
|
|
2013-12-17 15:30:21 +04:00
|
|
|
|
if (aFixedPosFrame != aViewportFrame) {
|
|
|
|
|
const nsStylePosition* position = aFixedPosFrame->StylePosition();
|
|
|
|
|
if (position->mOffset.GetRightUnit() != eStyleUnit_Auto) {
|
|
|
|
|
if (position->mOffset.GetLeftUnit() != eStyleUnit_Auto) {
|
|
|
|
|
anchor.x = anchorRect.x + anchorRect.width / 2.f;
|
|
|
|
|
} else {
|
|
|
|
|
anchor.x = anchorRect.XMost();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (position->mOffset.GetBottomUnit() != eStyleUnit_Auto) {
|
|
|
|
|
if (position->mOffset.GetTopUnit() != eStyleUnit_Auto) {
|
|
|
|
|
anchor.y = anchorRect.y + anchorRect.height / 2.f;
|
|
|
|
|
} else {
|
|
|
|
|
anchor.y = anchorRect.YMost();
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-27 10:02:03 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-18 02:44:42 +03:00
|
|
|
|
ViewID id = FrameMetrics::NULL_SCROLL_ID;
|
|
|
|
|
if (nsIFrame* rootScrollFrame = aPresContext->PresShell()->GetRootScrollFrame()) {
|
|
|
|
|
if (nsIContent* content = rootScrollFrame->GetContent()) {
|
|
|
|
|
id = FindOrCreateIDFor(content);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-18 21:27:18 +03:00
|
|
|
|
aLayer->SetFixedPositionData(id, anchor);
|
2013-09-27 10:02:03 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-17 15:30:21 +04:00
|
|
|
|
bool
|
|
|
|
|
nsLayoutUtils::ViewportHasDisplayPort(nsPresContext* aPresContext, nsRect* aDisplayPort)
|
|
|
|
|
{
|
|
|
|
|
nsIFrame* rootScrollFrame =
|
|
|
|
|
aPresContext->PresShell()->GetRootScrollFrame();
|
|
|
|
|
return rootScrollFrame &&
|
|
|
|
|
nsLayoutUtils::GetDisplayPort(rootScrollFrame->GetContent(), aDisplayPort);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-27 10:01:11 +04:00
|
|
|
|
bool
|
|
|
|
|
nsLayoutUtils::IsFixedPosFrameInDisplayPort(const nsIFrame* aFrame, nsRect* aDisplayPort)
|
|
|
|
|
{
|
|
|
|
|
// Fixed-pos frames are parented by the viewport frame or the page content frame.
|
|
|
|
|
// We'll assume that printing/print preview don't have displayports for their
|
|
|
|
|
// pages!
|
|
|
|
|
nsIFrame* parent = aFrame->GetParent();
|
|
|
|
|
if (!parent || parent->GetParent() ||
|
|
|
|
|
aFrame->StyleDisplay()->mPosition != NS_STYLE_POSITION_FIXED) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-12-17 15:30:21 +04:00
|
|
|
|
return ViewportHasDisplayPort(aFrame->PresContext(), aDisplayPort);
|
2013-09-27 10:01:11 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-04 16:44:26 +04:00
|
|
|
|
NS_DECLARE_FRAME_PROPERTY(ScrollbarThumbLayerized, nullptr)
|
|
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
|
nsLayoutUtils::SetScrollbarThumbLayerization(nsIFrame* aThumbFrame, bool aLayerize)
|
|
|
|
|
{
|
|
|
|
|
aThumbFrame->Properties().Set(ScrollbarThumbLayerized(),
|
|
|
|
|
reinterpret_cast<void*>(intptr_t(aLayerize)));
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-21 03:58:18 +03:00
|
|
|
|
bool
|
|
|
|
|
nsLayoutUtils::IsScrollbarThumbLayerized(nsIFrame* aThumbFrame)
|
2014-06-04 16:44:26 +04:00
|
|
|
|
{
|
|
|
|
|
return reinterpret_cast<intptr_t>(aThumbFrame->Properties().Get(ScrollbarThumbLayerized()));
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-23 08:21:42 +04:00
|
|
|
|
nsIFrame*
|
2014-10-22 05:54:06 +04:00
|
|
|
|
nsLayoutUtils::GetAnimatedGeometryRootForFrame(nsDisplayListBuilder* aBuilder,
|
|
|
|
|
nsIFrame* aFrame,
|
2014-06-23 08:21:42 +04:00
|
|
|
|
const nsIFrame* aStopAtAncestor)
|
2010-07-16 01:07:51 +04:00
|
|
|
|
{
|
2014-11-21 03:58:18 +03:00
|
|
|
|
return aBuilder->FindAnimatedGeometryRootFor(aFrame, aStopAtAncestor);
|
2010-07-16 01:07:51 +04:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-06 09:00:25 +04:00
|
|
|
|
nsIFrame*
|
2013-09-26 01:07:26 +04:00
|
|
|
|
nsLayoutUtils::GetAnimatedGeometryRootFor(nsDisplayItem* aItem,
|
2014-08-05 07:25:00 +04:00
|
|
|
|
nsDisplayListBuilder* aBuilder,
|
|
|
|
|
LayerManager* aManager)
|
2011-04-06 09:00:25 +04:00
|
|
|
|
{
|
2013-04-19 16:02:13 +04:00
|
|
|
|
nsIFrame* f = aItem->Frame();
|
2014-08-05 07:25:00 +04:00
|
|
|
|
if (aItem->ShouldFixToViewport(aManager)) {
|
2011-04-06 09:00:25 +04: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???");
|
2014-10-22 05:54:06 +04:00
|
|
|
|
return GetAnimatedGeometryRootForFrame(aBuilder, viewportFrame,
|
2013-09-26 01:07:26 +04:00
|
|
|
|
aBuilder->FindReferenceFrameFor(viewportFrame));
|
2011-04-06 09:00:25 +04:00
|
|
|
|
}
|
2014-10-22 05:54:06 +04:00
|
|
|
|
return GetAnimatedGeometryRootForFrame(aBuilder, f, aItem->ReferenceFrame());
|
2011-04-06 09:00:25 +04:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-01 15:29:27 +04:00
|
|
|
|
// static
|
|
|
|
|
nsIScrollableFrame*
|
|
|
|
|
nsLayoutUtils::GetNearestScrollableFrameForDirection(nsIFrame* aFrame,
|
|
|
|
|
Direction aDirection)
|
2004-10-19 06:24:27 +04:00
|
|
|
|
{
|
2009-09-01 15:29:27 +04: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) {
|
2013-08-24 00:20:07 +04:00
|
|
|
|
ScrollbarStyles ss = scrollableFrame->GetScrollbarStyles();
|
2012-09-24 08:30:33 +04:00
|
|
|
|
uint32_t directions = scrollableFrame->GetPerceivedScrollingDirections();
|
2009-09-01 15:29:27 +04:00
|
|
|
|
if (aDirection == eVertical ?
|
|
|
|
|
(ss.mVertical != NS_STYLE_OVERFLOW_HIDDEN &&
|
2012-09-24 08:30:33 +04:00
|
|
|
|
(directions & nsIScrollableFrame::VERTICAL)) :
|
2009-09-01 15:29:27 +04:00
|
|
|
|
(ss.mHorizontal != NS_STYLE_OVERFLOW_HIDDEN &&
|
2012-09-24 08:30:33 +04:00
|
|
|
|
(directions & nsIScrollableFrame::HORIZONTAL)))
|
2009-09-01 15:29:27 +04:00
|
|
|
|
return scrollableFrame;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
|
return nullptr;
|
2004-09-21 08:41:08 +04:00
|
|
|
|
}
|
|
|
|
|
|
2004-08-06 19:55:17 +04:00
|
|
|
|
// static
|
2009-09-01 15:29:27 +04:00
|
|
|
|
nsIScrollableFrame*
|
2013-07-31 08:01:06 +04:00
|
|
|
|
nsLayoutUtils::GetNearestScrollableFrame(nsIFrame* aFrame, uint32_t aFlags)
|
2004-08-06 19:55:17 +04:00
|
|
|
|
{
|
2009-09-01 15:29:27 +04:00
|
|
|
|
NS_ASSERTION(aFrame, "GetNearestScrollableFrame expects a non-null frame");
|
2013-07-31 08:01:06 +04:00
|
|
|
|
for (nsIFrame* f = aFrame; f; f = (aFlags & SCROLLABLE_SAME_DOC) ?
|
|
|
|
|
f->GetParent() : nsLayoutUtils::GetCrossDocParentFrame(f)) {
|
2009-09-01 15:29:27 +04:00
|
|
|
|
nsIScrollableFrame* scrollableFrame = do_QueryFrame(f);
|
|
|
|
|
if (scrollableFrame) {
|
2014-11-22 05:36:25 +03:00
|
|
|
|
if (aFlags & SCROLLABLE_ONLY_ASYNC_SCROLLABLE) {
|
|
|
|
|
if (scrollableFrame->WantAsyncScroll()) {
|
|
|
|
|
return scrollableFrame;
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2013-08-24 00:20:07 +04:00
|
|
|
|
ScrollbarStyles ss = scrollableFrame->GetScrollbarStyles();
|
2013-07-31 08:01:06 +04:00
|
|
|
|
if ((aFlags & SCROLLABLE_INCLUDE_HIDDEN) ||
|
|
|
|
|
ss.mVertical != NS_STYLE_OVERFLOW_HIDDEN ||
|
2009-09-01 15:29:27 +04:00
|
|
|
|
ss.mHorizontal != NS_STYLE_OVERFLOW_HIDDEN)
|
|
|
|
|
return scrollableFrame;
|
2004-08-06 19:55:17 +04:00
|
|
|
|
}
|
2014-11-22 05:36:25 +03:00
|
|
|
|
if (aFlags & SCROLLABLE_ALWAYS_MATCH_ROOT) {
|
2015-03-12 00:10:15 +03:00
|
|
|
|
nsIPresShell* ps = f->PresContext()->PresShell();
|
|
|
|
|
if (ps->GetDocument() && ps->GetDocument()->IsRootDisplayDocument() &&
|
|
|
|
|
ps->GetRootFrame() == f) {
|
|
|
|
|
return ps->GetRootScrollFrameAsScrollable();
|
2014-11-22 05:36:25 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2004-08-06 19:55:17 +04:00
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
|
return nullptr;
|
2004-08-06 19:55:17 +04:00
|
|
|
|
}
|
2004-11-25 17:51:00 +03:00
|
|
|
|
|
2013-01-29 05:38:22 +04:00
|
|
|
|
// static
|
|
|
|
|
nsRect
|
|
|
|
|
nsLayoutUtils::GetScrolledRect(nsIFrame* aScrolledFrame,
|
|
|
|
|
const nsRect& aScrolledFrameOverflowArea,
|
|
|
|
|
const nsSize& aScrollPortSize,
|
|
|
|
|
uint8_t aDirection)
|
|
|
|
|
{
|
|
|
|
|
nscoord x1 = aScrolledFrameOverflowArea.x,
|
|
|
|
|
x2 = aScrolledFrameOverflowArea.XMost(),
|
|
|
|
|
y1 = aScrolledFrameOverflowArea.y,
|
|
|
|
|
y2 = aScrolledFrameOverflowArea.YMost();
|
|
|
|
|
if (y1 < 0) {
|
|
|
|
|
y1 = 0;
|
|
|
|
|
}
|
|
|
|
|
if (aDirection != NS_STYLE_DIRECTION_RTL) {
|
|
|
|
|
if (x1 < 0) {
|
|
|
|
|
x1 = 0;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (x2 > aScrollPortSize.width) {
|
|
|
|
|
x2 = aScrollPortSize.width;
|
|
|
|
|
}
|
|
|
|
|
// When the scrolled frame chooses a size larger than its available width (because
|
|
|
|
|
// its padding alone is larger than the available width), we need to keep the
|
|
|
|
|
// start-edge of the scroll frame anchored to the start-edge of the scrollport.
|
|
|
|
|
// When the scrolled frame is RTL, this means moving it in our left-based
|
|
|
|
|
// coordinate system, so we need to compensate for its extra width here by
|
|
|
|
|
// effectively repositioning the frame.
|
|
|
|
|
nscoord extraWidth = std::max(0, aScrolledFrame->GetSize().width - aScrollPortSize.width);
|
|
|
|
|
x2 += extraWidth;
|
|
|
|
|
}
|
|
|
|
|
return nsRect(x1, y1, x2 - x1, y2 - y1);
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-06 02:11:23 +04:00
|
|
|
|
//static
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool
|
2010-08-06 02:11:23 +04: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 18:20:58 +04:00
|
|
|
|
return pseudoContext != nullptr;
|
2010-08-06 02:11:23 +04:00
|
|
|
|
}
|
|
|
|
|
|
2005-06-02 13:00:48 +04:00
|
|
|
|
nsPoint
|
|
|
|
|
nsLayoutUtils::GetDOMEventCoordinatesRelativeTo(nsIDOMEvent* aDOMEvent, nsIFrame* aFrame)
|
|
|
|
|
{
|
2012-06-11 03:44:50 +04:00
|
|
|
|
if (!aDOMEvent)
|
2005-06-02 13:00:48 +04:00
|
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
2013-10-02 07:46:04 +04:00
|
|
|
|
WidgetEvent* event = aDOMEvent->GetInternalNSEvent();
|
2008-10-10 03:23:07 +04:00
|
|
|
|
if (!event)
|
2005-06-02 13:00:48 +04:00
|
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
2005-08-23 07:57:07 +04:00
|
|
|
|
return GetEventCoordinatesRelativeTo(event, aFrame);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsPoint
|
2013-10-02 07:46:04 +04:00
|
|
|
|
nsLayoutUtils::GetEventCoordinatesRelativeTo(const WidgetEvent* aEvent,
|
|
|
|
|
nsIFrame* aFrame)
|
2005-08-23 07:57:07 +04:00
|
|
|
|
{
|
2014-08-04 09:28:50 +04:00
|
|
|
|
if (!aEvent || (aEvent->mClass != eMouseEventClass &&
|
2014-08-04 09:28:51 +04:00
|
|
|
|
aEvent->mClass != eMouseScrollEventClass &&
|
2014-08-04 09:28:51 +04:00
|
|
|
|
aEvent->mClass != eWheelEventClass &&
|
2014-08-04 09:28:50 +04:00
|
|
|
|
aEvent->mClass != eDragEventClass &&
|
2014-08-04 09:28:53 +04:00
|
|
|
|
aEvent->mClass != eSimpleGestureEventClass &&
|
2014-08-04 09:28:52 +04:00
|
|
|
|
aEvent->mClass != ePointerEventClass &&
|
2014-08-04 09:28:52 +04:00
|
|
|
|
aEvent->mClass != eGestureNotifyEventClass &&
|
2014-08-04 09:28:53 +04:00
|
|
|
|
aEvent->mClass != eTouchEventClass &&
|
2014-08-04 09:28:49 +04:00
|
|
|
|
aEvent->mClass != eQueryContentEventClass))
|
2005-06-02 13:00:48 +04:00
|
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
2005-08-23 07:57:07 +04:00
|
|
|
|
|
2011-12-17 04:24:11 +04:00
|
|
|
|
return GetEventCoordinatesRelativeTo(aEvent,
|
2015-02-02 01:27:31 +03:00
|
|
|
|
aEvent->AsGUIEvent()->refPoint,
|
2013-10-22 12:55:20 +04:00
|
|
|
|
aFrame);
|
2011-12-17 04:24:11 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsPoint
|
2013-10-02 07:46:04 +04:00
|
|
|
|
nsLayoutUtils::GetEventCoordinatesRelativeTo(const WidgetEvent* aEvent,
|
2015-02-02 01:27:31 +03:00
|
|
|
|
const LayoutDeviceIntPoint& aPoint,
|
2011-12-17 04:24:11 +04:00
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
if (!aFrame) {
|
|
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-22 12:55:20 +04:00
|
|
|
|
nsIWidget* widget = aEvent->AsGUIEvent()->widget;
|
2011-12-17 04:24:11 +04:00
|
|
|
|
if (!widget) {
|
|
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-11 01:02:23 +04:00
|
|
|
|
return GetEventCoordinatesRelativeTo(widget, aPoint, aFrame);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsPoint
|
|
|
|
|
nsLayoutUtils::GetEventCoordinatesRelativeTo(nsIWidget* aWidget,
|
2015-02-02 01:27:31 +03:00
|
|
|
|
const LayoutDeviceIntPoint& aPoint,
|
2012-09-11 01:02:23 +04:00
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
if (!aFrame || !aWidget) {
|
|
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
|
nsView* view = aFrame->GetView();
|
2012-03-04 01:24:13 +04:00
|
|
|
|
if (view) {
|
2012-03-06 19:58:36 +04:00
|
|
|
|
nsIWidget* frameWidget = view->GetWidget();
|
2012-09-11 01:02:23 +04:00
|
|
|
|
if (frameWidget && frameWidget == aWidget) {
|
2012-03-04 01:24:13 +04: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 19:58:36 +04:00
|
|
|
|
nsPoint pt(presContext->DevPixelsToAppUnits(aPoint.x),
|
|
|
|
|
presContext->DevPixelsToAppUnits(aPoint.y));
|
2012-03-04 01:24:13 +04:00
|
|
|
|
return pt - view->ViewToWidgetOffset();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-17 04:24:11 +04: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;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
|
nsView* rootView = rootFrame->GetView();
|
2011-12-17 04:24:11 +04:00
|
|
|
|
if (!rootView) {
|
|
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsPoint widgetToView = TranslateWidgetToView(rootFrame->PresContext(),
|
2012-09-11 01:02:23 +04:00
|
|
|
|
aWidget, aPoint, rootView);
|
2011-12-17 04:24:11 +04: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 19:56:38 +04:00
|
|
|
|
int32_t rootAPD = rootFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
|
int32_t localAPD = aFrame->PresContext()->AppUnitsPerDevPixel();
|
2015-03-27 00:44:40 +03:00
|
|
|
|
widgetToView = widgetToView.ScaleToOtherAppUnits(rootAPD, localAPD);
|
2011-12-17 04:24:11 +04:00
|
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
|
*/
|
2013-02-11 10:22:18 +04:00
|
|
|
|
if (transformFound || aFrame->IsSVGText()) {
|
2011-12-17 04:24:11 +04:00
|
|
|
|
return TransformRootPointToFrame(aFrame, widgetToView);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Otherwise, all coordinate systems are translations of one another,
|
2013-02-11 10:22:18 +04:00
|
|
|
|
* so we can just subtract out the difference.
|
2011-12-17 04:24:11 +04:00
|
|
|
|
*/
|
2013-02-11 10:22:18 +04:00
|
|
|
|
return widgetToView - aFrame->GetOffsetToCrossDoc(rootFrame);
|
2005-08-23 07:57:07 +04:00
|
|
|
|
}
|
|
|
|
|
|
2010-03-19 08:02:53 +03:00
|
|
|
|
nsIFrame*
|
2010-07-27 17:38:03 +04:00
|
|
|
|
nsLayoutUtils::GetPopupFrameForEventCoordinates(nsPresContext* aPresContext,
|
2013-10-02 07:46:04 +04:00
|
|
|
|
const WidgetEvent* aEvent)
|
2010-03-19 08:02:53 +03:00
|
|
|
|
{
|
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
|
if (!pm) {
|
2012-07-30 18:20:58 +04:00
|
|
|
|
return nullptr;
|
2010-03-19 08:02:53 +03:00
|
|
|
|
}
|
2012-11-29 20:14:13 +04:00
|
|
|
|
nsTArray<nsIFrame*> popups;
|
|
|
|
|
pm->GetVisiblePopups(popups);
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t i;
|
2010-03-19 08:02:53 +03:00
|
|
|
|
// Search from top to bottom
|
|
|
|
|
for (i = 0; i < popups.Length(); i++) {
|
|
|
|
|
nsIFrame* popup = popups[i];
|
2010-07-27 17:38:03 +04:00
|
|
|
|
if (popup->PresContext()->GetRootPresContext() == aPresContext &&
|
2010-10-07 08:25:47 +04:00
|
|
|
|
popup->GetScrollableOverflowRect().Contains(
|
2010-03-19 08:02:53 +03:00
|
|
|
|
GetEventCoordinatesRelativeTo(aEvent, popup))) {
|
|
|
|
|
return popup;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2012-07-30 18:20:58 +04:00
|
|
|
|
return nullptr;
|
2010-03-19 08:02:53 +03:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-31 15:53:54 +04:00
|
|
|
|
static void ConstrainToCoordValues(float& aStart, float& aSize)
|
|
|
|
|
{
|
2014-04-13 14:07:10 +04:00
|
|
|
|
MOZ_ASSERT(aSize >= 0);
|
2014-03-31 15:53:54 +04:00
|
|
|
|
|
|
|
|
|
// Here we try to make sure that the resulting nsRect will continue to cover
|
|
|
|
|
// as much of the area that was covered by the original gfx Rect as possible.
|
|
|
|
|
|
|
|
|
|
// We clamp the bounds of the rect to {nscoord_MIN,nscoord_MAX} since
|
|
|
|
|
// nsRect::X/Y() and nsRect::XMost/YMost() can't return values outwith this
|
|
|
|
|
// range:
|
|
|
|
|
float end = aStart + aSize;
|
|
|
|
|
aStart = clamped(aStart, float(nscoord_MIN), float(nscoord_MAX));
|
|
|
|
|
end = clamped(end, float(nscoord_MIN), float(nscoord_MAX));
|
|
|
|
|
|
|
|
|
|
aSize = end - aStart;
|
|
|
|
|
|
|
|
|
|
// We must also clamp aSize to {0,nscoord_MAX} since nsRect::Width/Height()
|
|
|
|
|
// can't return a value greater than nscoord_MAX. If aSize is greater than
|
|
|
|
|
// nscoord_MAX then we reduce it to nscoord_MAX while keeping the rect
|
|
|
|
|
// centered:
|
|
|
|
|
if (aSize > nscoord_MAX) {
|
|
|
|
|
float excess = aSize - nscoord_MAX;
|
|
|
|
|
excess /= 2;
|
|
|
|
|
aStart += excess;
|
|
|
|
|
aSize = nscoord_MAX;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
|
/**
|
|
|
|
|
* Given a gfxFloat, constrains its value to be between nscoord_MIN and nscoord_MAX.
|
|
|
|
|
*
|
|
|
|
|
* @param aVal The value to constrain (in/out)
|
|
|
|
|
*/
|
2014-02-17 02:25:36 +04:00
|
|
|
|
static void ConstrainToCoordValues(gfxFloat& aVal)
|
2008-09-13 13:42:11 +04:00
|
|
|
|
{
|
|
|
|
|
if (aVal <= nscoord_MIN)
|
|
|
|
|
aVal = nscoord_MIN;
|
|
|
|
|
else if (aVal >= nscoord_MAX)
|
|
|
|
|
aVal = nscoord_MAX;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-17 02:25:36 +04:00
|
|
|
|
static void ConstrainToCoordValues(gfxFloat& aStart, gfxFloat& aSize)
|
|
|
|
|
{
|
|
|
|
|
gfxFloat max = aStart + aSize;
|
|
|
|
|
|
|
|
|
|
// Clamp the end points to within nscoord range
|
|
|
|
|
ConstrainToCoordValues(aStart);
|
|
|
|
|
ConstrainToCoordValues(max);
|
|
|
|
|
|
|
|
|
|
aSize = max - aStart;
|
|
|
|
|
// If the width if still greater than the max nscoord, then bring both
|
|
|
|
|
// endpoints in by the same amount until it fits.
|
|
|
|
|
if (aSize > nscoord_MAX) {
|
|
|
|
|
gfxFloat excess = aSize - nscoord_MAX;
|
|
|
|
|
excess /= 2;
|
|
|
|
|
|
|
|
|
|
aStart += excess;
|
|
|
|
|
aSize = nscoord_MAX;
|
|
|
|
|
} else if (aSize < nscoord_MIN) {
|
|
|
|
|
gfxFloat excess = aSize - nscoord_MIN;
|
|
|
|
|
excess /= 2;
|
|
|
|
|
|
|
|
|
|
aStart -= excess;
|
|
|
|
|
aSize = nscoord_MIN;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-31 15:53:54 +04:00
|
|
|
|
nsRect
|
|
|
|
|
nsLayoutUtils::RoundGfxRectToAppRect(const Rect &aRect, float aFactor)
|
|
|
|
|
{
|
|
|
|
|
/* Get a new Rect whose units are app units by scaling by the specified factor. */
|
|
|
|
|
Rect scaledRect = aRect;
|
|
|
|
|
scaledRect.ScaleRoundOut(aFactor);
|
|
|
|
|
|
|
|
|
|
/* We now need to constrain our results to the max and min values for coords. */
|
|
|
|
|
ConstrainToCoordValues(scaledRect.x, scaledRect.width);
|
|
|
|
|
ConstrainToCoordValues(scaledRect.y, scaledRect.height);
|
|
|
|
|
|
|
|
|
|
/* Now typecast everything back. This is guaranteed to be safe. */
|
|
|
|
|
return nsRect(nscoord(scaledRect.X()), nscoord(scaledRect.Y()),
|
|
|
|
|
nscoord(scaledRect.Width()), nscoord(scaledRect.Height()));
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
|
nsRect
|
|
|
|
|
nsLayoutUtils::RoundGfxRectToAppRect(const gfxRect &aRect, float aFactor)
|
2010-04-27 20:15:01 +04:00
|
|
|
|
{
|
|
|
|
|
/* Get a new gfxRect whose units are app units by scaling by the specified factor. */
|
2011-04-19 07:07:48 +04:00
|
|
|
|
gfxRect scaledRect = aRect;
|
|
|
|
|
scaledRect.ScaleRoundOut(aFactor);
|
2008-09-13 13:42:11 +04:00
|
|
|
|
|
|
|
|
|
/* We now need to constrain our results to the max and min values for coords. */
|
2014-02-17 02:25:36 +04:00
|
|
|
|
ConstrainToCoordValues(scaledRect.x, scaledRect.width);
|
|
|
|
|
ConstrainToCoordValues(scaledRect.y, scaledRect.height);
|
2010-04-27 20:15:01 +04:00
|
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
|
/* Now typecast everything back. This is guaranteed to be safe. */
|
2011-04-19 07:07:21 +04:00
|
|
|
|
return nsRect(nscoord(scaledRect.X()), nscoord(scaledRect.Y()),
|
|
|
|
|
nscoord(scaledRect.Width()), nscoord(scaledRect.Height()));
|
2008-09-13 13:42:11 +04:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-03 04:48:09 +03: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;
|
2013-01-15 16:22:03 +04:00
|
|
|
|
nscoord xDiff = std::max(aRadii[NS_CORNER_TOP_LEFT_X], aRadii[NS_CORNER_BOTTOM_LEFT_X]);
|
2011-01-03 04:48:09 +03:00
|
|
|
|
rectFullHeight.x += xDiff;
|
2013-01-15 16:22:03 +04:00
|
|
|
|
rectFullHeight.width -= std::max(aRadii[NS_CORNER_TOP_RIGHT_X],
|
2011-01-03 04:48:09 +03:00
|
|
|
|
aRadii[NS_CORNER_BOTTOM_RIGHT_X]) + xDiff;
|
|
|
|
|
nsRect r1;
|
|
|
|
|
r1.IntersectRect(rectFullHeight, aContainedRect);
|
|
|
|
|
|
|
|
|
|
nsRect rectFullWidth = aRoundedRect;
|
2013-01-15 16:22:03 +04:00
|
|
|
|
nscoord yDiff = std::max(aRadii[NS_CORNER_TOP_LEFT_Y], aRadii[NS_CORNER_TOP_RIGHT_Y]);
|
2011-01-03 04:48:09 +03:00
|
|
|
|
rectFullWidth.y += yDiff;
|
2013-01-15 16:22:03 +04:00
|
|
|
|
rectFullWidth.height -= std::max(aRadii[NS_CORNER_BOTTOM_LEFT_Y],
|
2011-01-03 04:48:09 +03:00
|
|
|
|
aRadii[NS_CORNER_BOTTOM_RIGHT_Y]) + yDiff;
|
|
|
|
|
nsRect r2;
|
|
|
|
|
r2.IntersectRect(rectFullWidth, aContainedRect);
|
|
|
|
|
|
|
|
|
|
nsRegion result;
|
|
|
|
|
result.Or(r1, r2);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-23 10:12:08 +04:00
|
|
|
|
nsIntRegion
|
|
|
|
|
nsLayoutUtils::RoundedRectIntersectIntRect(const nsIntRect& aRoundedRect,
|
2014-11-01 13:45:10 +03:00
|
|
|
|
const RectCornerRadii& aCornerRadii,
|
2014-07-23 10:12:08 +04:00
|
|
|
|
const nsIntRect& aContainedRect)
|
|
|
|
|
{
|
|
|
|
|
// rectFullHeight and rectFullWidth together will approximately contain
|
|
|
|
|
// the total area of the frame minus the rounded corners.
|
|
|
|
|
nsIntRect rectFullHeight = aRoundedRect;
|
2014-11-01 13:45:10 +03:00
|
|
|
|
uint32_t xDiff = std::max(aCornerRadii.TopLeft().width,
|
|
|
|
|
aCornerRadii.BottomLeft().width);
|
2014-07-23 10:12:08 +04:00
|
|
|
|
rectFullHeight.x += xDiff;
|
2014-11-01 13:45:10 +03:00
|
|
|
|
rectFullHeight.width -= std::max(aCornerRadii.TopRight().width,
|
|
|
|
|
aCornerRadii.BottomRight().width) + xDiff;
|
2014-07-23 10:12:08 +04:00
|
|
|
|
nsIntRect r1;
|
|
|
|
|
r1.IntersectRect(rectFullHeight, aContainedRect);
|
|
|
|
|
|
|
|
|
|
nsIntRect rectFullWidth = aRoundedRect;
|
2014-11-01 13:45:10 +03:00
|
|
|
|
uint32_t yDiff = std::max(aCornerRadii.TopLeft().height,
|
|
|
|
|
aCornerRadii.TopRight().height);
|
2014-07-23 10:12:08 +04:00
|
|
|
|
rectFullWidth.y += yDiff;
|
2014-11-01 13:45:10 +03:00
|
|
|
|
rectFullWidth.height -= std::max(aCornerRadii.BottomLeft().height,
|
|
|
|
|
aCornerRadii.BottomRight().height) + yDiff;
|
2014-07-23 10:12:08 +04:00
|
|
|
|
nsIntRect r2;
|
|
|
|
|
r2.IntersectRect(rectFullWidth, aContainedRect);
|
|
|
|
|
|
|
|
|
|
nsIntRegion result;
|
|
|
|
|
result.Or(r1, r2);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-06 15:08:15 +04:00
|
|
|
|
// Helper for RoundedRectIntersectsRect.
|
|
|
|
|
static bool
|
|
|
|
|
CheckCorner(nscoord aXOffset, nscoord aYOffset,
|
|
|
|
|
nscoord aXRadius, nscoord aYRadius)
|
|
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
|
MOZ_ASSERT(aXOffset > 0 && aYOffset > 0,
|
|
|
|
|
"must not pass nonpositives to CheckCorner");
|
|
|
|
|
MOZ_ASSERT(aXRadius >= 0 && aYRadius >= 0,
|
|
|
|
|
"must not pass negatives to CheckCorner");
|
2013-03-06 15:08:15 +04:00
|
|
|
|
|
|
|
|
|
// Avoid floating point math unless we're either (1) within the
|
|
|
|
|
// quarter-ellipse area at the rounded corner or (2) outside the
|
|
|
|
|
// rounding.
|
|
|
|
|
if (aXOffset >= aXRadius || aYOffset >= aYRadius)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
// Convert coordinates to a unit circle with (0,0) as the center of
|
|
|
|
|
// curvature, and see if we're inside the circle or outside.
|
|
|
|
|
float scaledX = float(aXRadius - aXOffset) / float(aXRadius);
|
|
|
|
|
float scaledY = float(aYRadius - aYOffset) / float(aYRadius);
|
|
|
|
|
return scaledX * scaledX + scaledY * scaledY < 1.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
nsLayoutUtils::RoundedRectIntersectsRect(const nsRect& aRoundedRect,
|
|
|
|
|
const nscoord aRadii[8],
|
|
|
|
|
const nsRect& aTestRect)
|
|
|
|
|
{
|
|
|
|
|
if (!aTestRect.Intersects(aRoundedRect))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// distances from this edge of aRoundedRect to opposite edge of aTestRect,
|
|
|
|
|
// which we know are positive due to the Intersects check above.
|
|
|
|
|
nsMargin insets;
|
|
|
|
|
insets.top = aTestRect.YMost() - aRoundedRect.y;
|
|
|
|
|
insets.right = aRoundedRect.XMost() - aTestRect.x;
|
|
|
|
|
insets.bottom = aRoundedRect.YMost() - aTestRect.y;
|
|
|
|
|
insets.left = aTestRect.XMost() - aRoundedRect.x;
|
|
|
|
|
|
|
|
|
|
// Check whether the bottom-right corner of aTestRect is inside the
|
|
|
|
|
// top left corner of aBounds when rounded by aRadii, etc. If any
|
|
|
|
|
// corner is not, then fail; otherwise succeed.
|
|
|
|
|
return CheckCorner(insets.left, insets.top,
|
|
|
|
|
aRadii[NS_CORNER_TOP_LEFT_X],
|
|
|
|
|
aRadii[NS_CORNER_TOP_LEFT_Y]) &&
|
|
|
|
|
CheckCorner(insets.right, insets.top,
|
|
|
|
|
aRadii[NS_CORNER_TOP_RIGHT_X],
|
|
|
|
|
aRadii[NS_CORNER_TOP_RIGHT_Y]) &&
|
|
|
|
|
CheckCorner(insets.right, insets.bottom,
|
|
|
|
|
aRadii[NS_CORNER_BOTTOM_RIGHT_X],
|
|
|
|
|
aRadii[NS_CORNER_BOTTOM_RIGHT_Y]) &&
|
|
|
|
|
CheckCorner(insets.left, insets.bottom,
|
|
|
|
|
aRadii[NS_CORNER_BOTTOM_LEFT_X],
|
|
|
|
|
aRadii[NS_CORNER_BOTTOM_LEFT_Y]);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-25 01:55:23 +03:00
|
|
|
|
nsRect
|
|
|
|
|
nsLayoutUtils::MatrixTransformRectOut(const nsRect &aBounds,
|
2015-07-11 03:05:47 +03:00
|
|
|
|
const Matrix4x4 &aMatrix, float aFactor)
|
2011-02-25 01:55:23 +03:00
|
|
|
|
{
|
|
|
|
|
nsRect outside = aBounds;
|
|
|
|
|
outside.ScaleRoundOut(1/aFactor);
|
2015-07-11 03:05:47 +03:00
|
|
|
|
gfxRect image = gfxRect(outside.x, outside.y, outside.width, outside.height);
|
|
|
|
|
image.TransformBounds(aMatrix);
|
2011-02-25 01:55:23 +03:00
|
|
|
|
return RoundGfxRectToAppRect(image, aFactor);
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
|
nsRect
|
|
|
|
|
nsLayoutUtils::MatrixTransformRect(const nsRect &aBounds,
|
2015-07-11 03:05:47 +03:00
|
|
|
|
const Matrix4x4 &aMatrix, float aFactor)
|
2008-09-13 13:42:11 +04:00
|
|
|
|
{
|
2015-07-11 03:05:47 +03:00
|
|
|
|
gfxRect image = gfxRect(NSAppUnitsToDoublePixels(aBounds.x, aFactor),
|
|
|
|
|
NSAppUnitsToDoublePixels(aBounds.y, aFactor),
|
|
|
|
|
NSAppUnitsToDoublePixels(aBounds.width, aFactor),
|
|
|
|
|
NSAppUnitsToDoublePixels(aBounds.height, aFactor));
|
|
|
|
|
image.TransformBounds(aMatrix);
|
2010-04-27 20:15:01 +04:00
|
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
|
return RoundGfxRectToAppRect(image, aFactor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsPoint
|
|
|
|
|
nsLayoutUtils::MatrixTransformPoint(const nsPoint &aPoint,
|
2015-07-11 03:05:47 +03:00
|
|
|
|
const Matrix4x4 &aMatrix, float aFactor)
|
2008-09-13 13:42:11 +04:00
|
|
|
|
{
|
2015-07-11 03:05:47 +03:00
|
|
|
|
gfxPoint image = gfxPoint(NSAppUnitsToFloatPixels(aPoint.x, aFactor),
|
|
|
|
|
NSAppUnitsToFloatPixels(aPoint.y, aFactor));
|
|
|
|
|
image.Transform(aMatrix);
|
2008-09-13 13:42:11 +04:00
|
|
|
|
return nsPoint(NSFloatPixelsToAppUnits(float(image.x), aFactor),
|
|
|
|
|
NSFloatPixelsToAppUnits(float(image.y), aFactor));
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-22 17:40:02 +04:00
|
|
|
|
Matrix4x4
|
2012-09-13 04:32:53 +04:00
|
|
|
|
nsLayoutUtils::GetTransformToAncestor(nsIFrame *aFrame, const nsIFrame *aAncestor)
|
2008-09-13 13:42:11 +04:00
|
|
|
|
{
|
2011-12-28 07:24:18 +04:00
|
|
|
|
nsIFrame* parent;
|
2014-08-22 17:40:02 +04:00
|
|
|
|
Matrix4x4 ctm;
|
2012-10-17 07:13:24 +04:00
|
|
|
|
if (aFrame == aAncestor) {
|
|
|
|
|
return ctm;
|
|
|
|
|
}
|
|
|
|
|
ctm = aFrame->GetTransformMatrix(aAncestor, &parent);
|
2011-12-28 07:24:18 +04:00
|
|
|
|
while (parent && parent != aAncestor) {
|
2012-02-08 23:36:16 +04:00
|
|
|
|
if (!parent->Preserves3DChildren()) {
|
|
|
|
|
ctm.ProjectTo2D();
|
|
|
|
|
}
|
2011-12-28 07:24:18 +04:00
|
|
|
|
ctm = ctm * parent->GetTransformMatrix(aAncestor, &parent);
|
2011-05-09 12:40:09 +04:00
|
|
|
|
}
|
2011-12-28 07:24:18 +04:00
|
|
|
|
return ctm;
|
|
|
|
|
}
|
2011-08-03 07:04:21 +04:00
|
|
|
|
|
2014-10-24 23:49:38 +04:00
|
|
|
|
gfxSize
|
|
|
|
|
nsLayoutUtils::GetTransformToAncestorScale(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
Matrix4x4 transform = GetTransformToAncestor(aFrame,
|
|
|
|
|
nsLayoutUtils::GetDisplayRootFrame(aFrame));
|
|
|
|
|
Matrix transform2D;
|
|
|
|
|
if (transform.Is2D(&transform2D)) {
|
|
|
|
|
return ThebesMatrix(transform2D).ScaleFactors(true);
|
|
|
|
|
}
|
|
|
|
|
return gfxSize(1, 1);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-20 05:30:40 +03:00
|
|
|
|
static Matrix4x4
|
|
|
|
|
GetTransformToAncestorExcludingAnimated(nsIFrame* aFrame,
|
|
|
|
|
const nsIFrame* aAncestor)
|
|
|
|
|
{
|
|
|
|
|
nsIFrame* parent;
|
|
|
|
|
Matrix4x4 ctm;
|
|
|
|
|
if (aFrame == aAncestor) {
|
|
|
|
|
return ctm;
|
|
|
|
|
}
|
|
|
|
|
if (ActiveLayerTracker::IsScaleSubjectToAnimation(aFrame)) {
|
|
|
|
|
return ctm;
|
|
|
|
|
}
|
|
|
|
|
ctm = aFrame->GetTransformMatrix(aAncestor, &parent);
|
|
|
|
|
while (parent && parent != aAncestor) {
|
|
|
|
|
if (ActiveLayerTracker::IsScaleSubjectToAnimation(parent)) {
|
|
|
|
|
return Matrix4x4();
|
|
|
|
|
}
|
|
|
|
|
if (!parent->Preserves3DChildren()) {
|
|
|
|
|
ctm.ProjectTo2D();
|
|
|
|
|
}
|
|
|
|
|
ctm = ctm * parent->GetTransformMatrix(aAncestor, &parent);
|
|
|
|
|
}
|
|
|
|
|
return ctm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gfxSize
|
|
|
|
|
nsLayoutUtils::GetTransformToAncestorScaleExcludingAnimated(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
Matrix4x4 transform = GetTransformToAncestorExcludingAnimated(aFrame,
|
|
|
|
|
nsLayoutUtils::GetDisplayRootFrame(aFrame));
|
|
|
|
|
Matrix transform2D;
|
|
|
|
|
if (transform.Is2D(&transform2D)) {
|
|
|
|
|
return ThebesMatrix(transform2D).ScaleFactors(true);
|
|
|
|
|
}
|
|
|
|
|
return gfxSize(1, 1);
|
|
|
|
|
}
|
2014-10-24 23:49:38 +04:00
|
|
|
|
|
2014-12-10 21:52:00 +03:00
|
|
|
|
nsIFrame*
|
|
|
|
|
nsLayoutUtils::FindNearestCommonAncestorFrame(nsIFrame* aFrame1, nsIFrame* aFrame2)
|
2013-09-20 14:21:03 +04:00
|
|
|
|
{
|
|
|
|
|
nsAutoTArray<nsIFrame*,100> ancestors1;
|
|
|
|
|
nsAutoTArray<nsIFrame*,100> ancestors2;
|
|
|
|
|
nsIFrame* commonAncestor = nullptr;
|
|
|
|
|
if (aFrame1->PresContext() == aFrame2->PresContext()) {
|
|
|
|
|
commonAncestor = aFrame1->PresContext()->PresShell()->GetRootFrame();
|
|
|
|
|
}
|
|
|
|
|
for (nsIFrame* f = aFrame1; f != commonAncestor;
|
|
|
|
|
f = nsLayoutUtils::GetCrossDocParentFrame(f)) {
|
|
|
|
|
ancestors1.AppendElement(f);
|
|
|
|
|
}
|
|
|
|
|
for (nsIFrame* f = aFrame2; f != commonAncestor;
|
|
|
|
|
f = nsLayoutUtils::GetCrossDocParentFrame(f)) {
|
|
|
|
|
ancestors2.AppendElement(f);
|
|
|
|
|
}
|
|
|
|
|
uint32_t minLengths = std::min(ancestors1.Length(), ancestors2.Length());
|
|
|
|
|
for (uint32_t i = 1; i <= minLengths; ++i) {
|
|
|
|
|
if (ancestors1[ancestors1.Length() - i] == ancestors2[ancestors2.Length() - i]) {
|
|
|
|
|
commonAncestor = ancestors1[ancestors1.Length() - i];
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return commonAncestor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsLayoutUtils::TransformResult
|
|
|
|
|
nsLayoutUtils::TransformPoints(nsIFrame* aFromFrame, nsIFrame* aToFrame,
|
|
|
|
|
uint32_t aPointCount, CSSPoint* aPoints)
|
|
|
|
|
{
|
|
|
|
|
nsIFrame* nearestCommonAncestor = FindNearestCommonAncestorFrame(aFromFrame, aToFrame);
|
|
|
|
|
if (!nearestCommonAncestor) {
|
|
|
|
|
return NO_COMMON_ANCESTOR;
|
|
|
|
|
}
|
2014-08-22 17:40:02 +04:00
|
|
|
|
Matrix4x4 downToDest = GetTransformToAncestor(aToFrame, nearestCommonAncestor);
|
2013-09-20 14:21:03 +04:00
|
|
|
|
if (downToDest.IsSingular()) {
|
|
|
|
|
return NONINVERTIBLE_TRANSFORM;
|
|
|
|
|
}
|
|
|
|
|
downToDest.Invert();
|
2014-08-22 17:40:02 +04:00
|
|
|
|
Matrix4x4 upToAncestor = GetTransformToAncestor(aFromFrame, nearestCommonAncestor);
|
2013-09-20 14:21:03 +04:00
|
|
|
|
CSSToLayoutDeviceScale devPixelsPerCSSPixelFromFrame(
|
|
|
|
|
double(nsPresContext::AppUnitsPerCSSPixel())/
|
|
|
|
|
aFromFrame->PresContext()->AppUnitsPerDevPixel());
|
|
|
|
|
CSSToLayoutDeviceScale devPixelsPerCSSPixelToFrame(
|
|
|
|
|
double(nsPresContext::AppUnitsPerCSSPixel())/
|
|
|
|
|
aToFrame->PresContext()->AppUnitsPerDevPixel());
|
|
|
|
|
for (uint32_t i = 0; i < aPointCount; ++i) {
|
|
|
|
|
LayoutDevicePoint devPixels = aPoints[i] * devPixelsPerCSSPixelFromFrame;
|
2014-07-08 08:55:42 +04:00
|
|
|
|
// What should the behaviour be if some of the points aren't invertible
|
|
|
|
|
// and others are? Just assume all points are for now.
|
2014-08-22 17:40:02 +04:00
|
|
|
|
Point toDevPixels = downToDest.ProjectPoint(
|
|
|
|
|
(upToAncestor * Point(devPixels.x, devPixels.y))).As2DPoint();
|
2013-09-20 14:21:03 +04:00
|
|
|
|
// Divide here so that when the devPixelsPerCSSPixels are the same, we get the correct
|
|
|
|
|
// answer instead of some inaccuracy multiplying a number by its reciprocal.
|
|
|
|
|
aPoints[i] = LayoutDevicePoint(toDevPixels.x, toDevPixels.y) /
|
|
|
|
|
devPixelsPerCSSPixelToFrame;
|
|
|
|
|
}
|
|
|
|
|
return TRANSFORM_SUCCEEDED;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-03 11:08:37 +04:00
|
|
|
|
nsLayoutUtils::TransformResult
|
|
|
|
|
nsLayoutUtils::TransformPoint(nsIFrame* aFromFrame, nsIFrame* aToFrame,
|
|
|
|
|
nsPoint& aPoint)
|
|
|
|
|
{
|
|
|
|
|
nsIFrame* nearestCommonAncestor = FindNearestCommonAncestorFrame(aFromFrame, aToFrame);
|
|
|
|
|
if (!nearestCommonAncestor) {
|
|
|
|
|
return NO_COMMON_ANCESTOR;
|
|
|
|
|
}
|
2014-08-22 17:40:02 +04:00
|
|
|
|
Matrix4x4 downToDest = GetTransformToAncestor(aToFrame, nearestCommonAncestor);
|
2014-06-03 11:08:37 +04:00
|
|
|
|
if (downToDest.IsSingular()) {
|
|
|
|
|
return NONINVERTIBLE_TRANSFORM;
|
|
|
|
|
}
|
|
|
|
|
downToDest.Invert();
|
2014-08-22 17:40:02 +04:00
|
|
|
|
Matrix4x4 upToAncestor = GetTransformToAncestor(aFromFrame, nearestCommonAncestor);
|
2014-06-03 11:08:37 +04:00
|
|
|
|
|
|
|
|
|
float devPixelsPerAppUnitFromFrame =
|
|
|
|
|
1.0f / aFromFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
|
float devPixelsPerAppUnitToFrame =
|
|
|
|
|
1.0f / aToFrame->PresContext()->AppUnitsPerDevPixel();
|
2014-08-22 17:40:02 +04:00
|
|
|
|
Point4D toDevPixels = downToDest.ProjectPoint(
|
|
|
|
|
upToAncestor * Point(aPoint.x * devPixelsPerAppUnitFromFrame,
|
|
|
|
|
aPoint.y * devPixelsPerAppUnitFromFrame));
|
2014-07-08 08:55:42 +04:00
|
|
|
|
if (!toDevPixels.HasPositiveWCoord()) {
|
|
|
|
|
// Not strictly true, but we failed to get a valid point in this
|
|
|
|
|
// coordinate space.
|
|
|
|
|
return NONINVERTIBLE_TRANSFORM;
|
|
|
|
|
}
|
2015-03-13 14:50:10 +03:00
|
|
|
|
aPoint.x = NSToCoordRound(toDevPixels.x / devPixelsPerAppUnitToFrame);
|
|
|
|
|
aPoint.y = NSToCoordRound(toDevPixels.y / devPixelsPerAppUnitToFrame);
|
2014-06-03 11:08:37 +04:00
|
|
|
|
return TRANSFORM_SUCCEEDED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsLayoutUtils::TransformResult
|
|
|
|
|
nsLayoutUtils::TransformRect(nsIFrame* aFromFrame, nsIFrame* aToFrame,
|
|
|
|
|
nsRect& aRect)
|
|
|
|
|
{
|
|
|
|
|
nsIFrame* nearestCommonAncestor = FindNearestCommonAncestorFrame(aFromFrame, aToFrame);
|
|
|
|
|
if (!nearestCommonAncestor) {
|
|
|
|
|
return NO_COMMON_ANCESTOR;
|
|
|
|
|
}
|
2014-08-22 17:40:02 +04:00
|
|
|
|
Matrix4x4 downToDest = GetTransformToAncestor(aToFrame, nearestCommonAncestor);
|
2014-06-03 11:08:37 +04:00
|
|
|
|
if (downToDest.IsSingular()) {
|
|
|
|
|
return NONINVERTIBLE_TRANSFORM;
|
|
|
|
|
}
|
|
|
|
|
downToDest.Invert();
|
2014-08-22 17:40:02 +04:00
|
|
|
|
Matrix4x4 upToAncestor = GetTransformToAncestor(aFromFrame, nearestCommonAncestor);
|
2014-06-03 11:08:37 +04:00
|
|
|
|
|
|
|
|
|
float devPixelsPerAppUnitFromFrame =
|
|
|
|
|
1.0f / aFromFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
|
float devPixelsPerAppUnitToFrame =
|
|
|
|
|
1.0f / aToFrame->PresContext()->AppUnitsPerDevPixel();
|
2014-08-22 17:40:02 +04:00
|
|
|
|
gfx::Rect toDevPixels = downToDest.ProjectRectBounds(
|
2014-06-03 11:08:37 +04:00
|
|
|
|
upToAncestor.ProjectRectBounds(
|
2014-08-22 17:40:02 +04:00
|
|
|
|
gfx::Rect(aRect.x * devPixelsPerAppUnitFromFrame,
|
|
|
|
|
aRect.y * devPixelsPerAppUnitFromFrame,
|
|
|
|
|
aRect.width * devPixelsPerAppUnitFromFrame,
|
2015-03-13 23:42:00 +03:00
|
|
|
|
aRect.height * devPixelsPerAppUnitFromFrame),
|
|
|
|
|
Rect(-std::numeric_limits<Float>::max() * 0.5f,
|
|
|
|
|
-std::numeric_limits<Float>::max() * 0.5f,
|
|
|
|
|
std::numeric_limits<Float>::max(),
|
|
|
|
|
std::numeric_limits<Float>::max())),
|
|
|
|
|
Rect(-std::numeric_limits<Float>::max() * devPixelsPerAppUnitFromFrame * 0.5f,
|
|
|
|
|
-std::numeric_limits<Float>::max() * devPixelsPerAppUnitFromFrame * 0.5f,
|
|
|
|
|
std::numeric_limits<Float>::max() * devPixelsPerAppUnitFromFrame,
|
|
|
|
|
std::numeric_limits<Float>::max() * devPixelsPerAppUnitFromFrame));
|
2014-06-03 11:08:37 +04:00
|
|
|
|
aRect.x = toDevPixels.x / devPixelsPerAppUnitToFrame;
|
|
|
|
|
aRect.y = toDevPixels.y / devPixelsPerAppUnitToFrame;
|
|
|
|
|
aRect.width = toDevPixels.width / devPixelsPerAppUnitToFrame;
|
|
|
|
|
aRect.height = toDevPixels.height / devPixelsPerAppUnitToFrame;
|
|
|
|
|
return TRANSFORM_SUCCEEDED;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-15 19:07:00 +04:00
|
|
|
|
nsRect
|
|
|
|
|
nsLayoutUtils::GetRectRelativeToFrame(Element* aElement, nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
if (!aElement || !aFrame) {
|
|
|
|
|
return nsRect();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIFrame* frame = aElement->GetPrimaryFrame();
|
|
|
|
|
if (!frame) {
|
|
|
|
|
return nsRect();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsRect rect = frame->GetRectRelativeToSelf();
|
|
|
|
|
nsLayoutUtils::TransformResult rv =
|
|
|
|
|
nsLayoutUtils::TransformRect(frame, aFrame, rect);
|
|
|
|
|
if (rv != nsLayoutUtils::TRANSFORM_SUCCEEDED) {
|
|
|
|
|
return nsRect();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rect;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-15 04:57:00 +04:00
|
|
|
|
bool
|
|
|
|
|
nsLayoutUtils::ContainsPoint(const nsRect& aRect, const nsPoint& aPoint,
|
|
|
|
|
nscoord aInflateSize)
|
|
|
|
|
{
|
|
|
|
|
nsRect rect = aRect;
|
|
|
|
|
rect.Inflate(aInflateSize);
|
|
|
|
|
return rect.Contains(aPoint);
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-08 03:53:00 +03:00
|
|
|
|
bool
|
|
|
|
|
nsLayoutUtils::IsRectVisibleInScrollFrames(nsIFrame* aFrame, const nsRect& aRect)
|
2015-04-14 01:08:00 +03:00
|
|
|
|
{
|
|
|
|
|
return !ClampRectToScrollFrames(aFrame, aRect).IsEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
|
nsLayoutUtils::ClampRectToScrollFrames(nsIFrame* aFrame, const nsRect& aRect)
|
2014-12-08 03:53:00 +03:00
|
|
|
|
{
|
|
|
|
|
nsIFrame* closestScrollFrame =
|
|
|
|
|
nsLayoutUtils::GetClosestFrameOfType(aFrame, nsGkAtoms::scrollFrame);
|
|
|
|
|
|
2015-04-14 01:08:00 +03:00
|
|
|
|
nsRect resultRect = aRect;
|
|
|
|
|
|
2014-12-08 03:53:00 +03:00
|
|
|
|
while (closestScrollFrame) {
|
|
|
|
|
nsIScrollableFrame* sf = do_QueryFrame(closestScrollFrame);
|
2015-04-14 01:08:00 +03:00
|
|
|
|
|
2014-12-08 03:53:00 +03:00
|
|
|
|
nsRect scrollPortRect = sf->GetScrollPortRect();
|
2015-04-14 01:08:00 +03:00
|
|
|
|
nsLayoutUtils::TransformRect(closestScrollFrame, aFrame, scrollPortRect);
|
2014-12-08 03:53:00 +03:00
|
|
|
|
|
2015-04-14 01:08:00 +03:00
|
|
|
|
resultRect = resultRect.Intersect(scrollPortRect);
|
2014-12-08 03:53:00 +03:00
|
|
|
|
|
|
|
|
|
// Check whether aRect is visible in the scroll frame or not.
|
2015-04-14 01:08:00 +03:00
|
|
|
|
if (resultRect.IsEmpty()) {
|
|
|
|
|
break;
|
2014-12-08 03:53:00 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get next ancestor scroll frame.
|
|
|
|
|
closestScrollFrame =
|
|
|
|
|
nsLayoutUtils::GetClosestFrameOfType(closestScrollFrame->GetParent(),
|
|
|
|
|
nsGkAtoms::scrollFrame);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-14 01:08:00 +03:00
|
|
|
|
return resultRect;
|
2014-12-08 03:53:00 +03:00
|
|
|
|
}
|
|
|
|
|
|
2012-10-03 09:55:50 +04:00
|
|
|
|
bool
|
|
|
|
|
nsLayoutUtils::GetLayerTransformForFrame(nsIFrame* aFrame,
|
2014-08-22 17:40:02 +04:00
|
|
|
|
Matrix4x4* aTransform)
|
2012-10-03 09:55:50 +04:00
|
|
|
|
{
|
|
|
|
|
// FIXME/bug 796690: we can sometimes compute a transform in these
|
|
|
|
|
// cases, it just increases complexity considerably. Punt for now.
|
|
|
|
|
if (aFrame->Preserves3DChildren() || aFrame->HasTransformGetter()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIFrame* root = nsLayoutUtils::GetDisplayRootFrame(aFrame);
|
|
|
|
|
if (root->HasAnyStateBits(NS_FRAME_UPDATE_LAYER_TREE)) {
|
|
|
|
|
// Content may have been invalidated, so we can't reliably compute
|
|
|
|
|
// the "layer transform" in general.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// If the caller doesn't care about the value, early-return to skip
|
|
|
|
|
// overhead below.
|
|
|
|
|
if (!aTransform) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsDisplayListBuilder builder(root, nsDisplayListBuilder::OTHER,
|
|
|
|
|
false/*don't build caret*/);
|
|
|
|
|
nsDisplayList list;
|
|
|
|
|
nsDisplayTransform* item =
|
2014-07-15 15:47:46 +04:00
|
|
|
|
new (&builder) nsDisplayTransform(&builder, aFrame, &list, nsRect());
|
2012-10-03 09:55:50 +04:00
|
|
|
|
|
2014-08-22 17:40:02 +04:00
|
|
|
|
*aTransform = item->GetTransform();
|
2012-10-03 09:55:52 +04:00
|
|
|
|
item->~nsDisplayTransform();
|
2012-10-03 09:55:50 +04:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-04 03:25:23 +04:00
|
|
|
|
static bool
|
2011-12-28 07:24:18 +04:00
|
|
|
|
TransformGfxPointFromAncestor(nsIFrame *aFrame,
|
2014-08-22 17:40:02 +04:00
|
|
|
|
const Point &aPoint,
|
2014-02-04 03:25:23 +04:00
|
|
|
|
nsIFrame *aAncestor,
|
2014-08-22 17:40:02 +04:00
|
|
|
|
Point* aOut)
|
2011-12-28 07:24:18 +04:00
|
|
|
|
{
|
2014-08-22 17:40:02 +04:00
|
|
|
|
Matrix4x4 ctm = nsLayoutUtils::GetTransformToAncestor(aFrame, aAncestor);
|
|
|
|
|
ctm.Invert();
|
|
|
|
|
Point4D point = ctm.ProjectPoint(aPoint);
|
2014-07-08 08:55:42 +04:00
|
|
|
|
if (!point.HasPositiveWCoord()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
*aOut = point.As2DPoint();
|
|
|
|
|
return true;
|
2014-01-31 09:44:41 +04:00
|
|
|
|
}
|
2014-01-29 04:10:35 +04:00
|
|
|
|
|
2014-08-22 17:40:02 +04:00
|
|
|
|
static Rect
|
2011-12-28 07:24:18 +04:00
|
|
|
|
TransformGfxRectToAncestor(nsIFrame *aFrame,
|
2014-08-22 17:40:02 +04:00
|
|
|
|
const Rect &aRect,
|
2013-07-30 20:22:46 +04:00
|
|
|
|
const nsIFrame *aAncestor,
|
|
|
|
|
bool* aPreservesAxisAlignedRectangles = nullptr)
|
2011-12-28 07:24:18 +04:00
|
|
|
|
{
|
2014-08-22 17:40:02 +04:00
|
|
|
|
Matrix4x4 ctm = nsLayoutUtils::GetTransformToAncestor(aFrame, aAncestor);
|
2013-07-30 20:22:46 +04:00
|
|
|
|
if (aPreservesAxisAlignedRectangles) {
|
2014-08-22 17:40:02 +04:00
|
|
|
|
Matrix matrix2d;
|
2013-07-30 20:22:46 +04:00
|
|
|
|
*aPreservesAxisAlignedRectangles =
|
|
|
|
|
ctm.Is2D(&matrix2d) && matrix2d.PreservesAxisAlignedRectangles();
|
|
|
|
|
}
|
2012-01-23 05:07:37 +04:00
|
|
|
|
return ctm.TransformBounds(aRect);
|
2011-08-03 07:04:21 +04:00
|
|
|
|
}
|
2008-09-13 13:42:11 +04:00
|
|
|
|
|
2013-12-20 20:38:51 +04:00
|
|
|
|
static SVGTextFrame*
|
2013-02-11 10:22:18 +04:00
|
|
|
|
GetContainingSVGTextFrame(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
if (!aFrame->IsSVGText()) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-20 20:38:51 +04:00
|
|
|
|
return static_cast<SVGTextFrame*>
|
2013-02-11 10:22:18 +04:00
|
|
|
|
(nsLayoutUtils::GetClosestFrameOfType(aFrame->GetParent(),
|
2013-12-20 20:38:51 +04:00
|
|
|
|
nsGkAtoms::svgTextFrame));
|
2013-02-11 10:22:18 +04:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-03 07:04:21 +04:00
|
|
|
|
nsPoint
|
2013-02-11 10:22:18 +04:00
|
|
|
|
nsLayoutUtils::TransformAncestorPointToFrame(nsIFrame* aFrame,
|
|
|
|
|
const nsPoint& aPoint,
|
|
|
|
|
nsIFrame* aAncestor)
|
2011-08-03 07:04:21 +04:00
|
|
|
|
{
|
2013-12-20 20:38:51 +04:00
|
|
|
|
SVGTextFrame* text = GetContainingSVGTextFrame(aFrame);
|
2013-02-11 10:22:18 +04:00
|
|
|
|
|
2011-08-03 07:04:21 +04:00
|
|
|
|
float factor = aFrame->PresContext()->AppUnitsPerDevPixel();
|
2014-08-22 17:40:02 +04:00
|
|
|
|
Point result(NSAppUnitsToFloatPixels(aPoint.x, factor),
|
|
|
|
|
NSAppUnitsToFloatPixels(aPoint.y, factor));
|
2012-10-12 04:11:37 +04:00
|
|
|
|
|
2013-02-11 10:22:18 +04:00
|
|
|
|
if (text) {
|
2014-02-04 03:25:23 +04:00
|
|
|
|
if (!TransformGfxPointFromAncestor(text, result, aAncestor, &result)) {
|
|
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
|
}
|
2013-02-11 10:22:18 +04:00
|
|
|
|
result = text->TransformFramePointToTextChild(result, aFrame);
|
|
|
|
|
} else {
|
2014-02-04 03:25:23 +04:00
|
|
|
|
if (!TransformGfxPointFromAncestor(aFrame, result, nullptr, &result)) {
|
|
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
|
}
|
2013-02-11 10:22:18 +04:00
|
|
|
|
}
|
2012-10-12 04:11:37 +04:00
|
|
|
|
|
2011-08-03 07:04:21 +04:00
|
|
|
|
return nsPoint(NSFloatPixelsToAppUnits(float(result.x), factor),
|
|
|
|
|
NSFloatPixelsToAppUnits(float(result.y), factor));
|
|
|
|
|
}
|
2011-07-23 02:28:51 +04:00
|
|
|
|
|
2011-12-28 07:24:18 +04:00
|
|
|
|
nsRect
|
|
|
|
|
nsLayoutUtils::TransformFrameRectToAncestor(nsIFrame* aFrame,
|
|
|
|
|
const nsRect& aRect,
|
2013-07-30 20:22:46 +04:00
|
|
|
|
const nsIFrame* aAncestor,
|
|
|
|
|
bool* aPreservesAxisAlignedRectangles /* = nullptr */)
|
2011-12-28 07:24:18 +04:00
|
|
|
|
{
|
2013-12-20 20:38:51 +04:00
|
|
|
|
SVGTextFrame* text = GetContainingSVGTextFrame(aFrame);
|
2013-02-11 10:22:18 +04:00
|
|
|
|
|
2012-10-12 04:11:37 +04:00
|
|
|
|
float srcAppUnitsPerDevPixel = aFrame->PresContext()->AppUnitsPerDevPixel();
|
2014-08-22 17:40:02 +04:00
|
|
|
|
Rect result;
|
2011-12-28 07:24:18 +04:00
|
|
|
|
|
2013-02-11 10:22:18 +04:00
|
|
|
|
if (text) {
|
2014-08-22 17:40:02 +04:00
|
|
|
|
result = ToRect(text->TransformFrameRectFromTextChild(aRect, aFrame));
|
2013-02-11 10:22:18 +04:00
|
|
|
|
result = TransformGfxRectToAncestor(text, result, aAncestor);
|
2013-07-30 20:22:46 +04:00
|
|
|
|
// TransformFrameRectFromTextChild could involve any kind of transform, we
|
|
|
|
|
// could drill down into it to get an answer out of it but we don't yet.
|
|
|
|
|
if (aPreservesAxisAlignedRectangles)
|
|
|
|
|
*aPreservesAxisAlignedRectangles = false;
|
2013-02-11 10:22:18 +04:00
|
|
|
|
} else {
|
2014-08-22 17:40:02 +04:00
|
|
|
|
result = Rect(NSAppUnitsToFloatPixels(aRect.x, srcAppUnitsPerDevPixel),
|
|
|
|
|
NSAppUnitsToFloatPixels(aRect.y, srcAppUnitsPerDevPixel),
|
|
|
|
|
NSAppUnitsToFloatPixels(aRect.width, srcAppUnitsPerDevPixel),
|
|
|
|
|
NSAppUnitsToFloatPixels(aRect.height, srcAppUnitsPerDevPixel));
|
2013-07-30 20:22:46 +04:00
|
|
|
|
result = TransformGfxRectToAncestor(aFrame, result, aAncestor, aPreservesAxisAlignedRectangles);
|
2013-02-11 10:22:18 +04:00
|
|
|
|
}
|
2011-12-28 07:24:18 +04:00
|
|
|
|
|
2012-10-12 04:11:37 +04:00
|
|
|
|
float destAppUnitsPerDevPixel = aAncestor->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
|
return nsRect(NSFloatPixelsToAppUnits(float(result.x), destAppUnitsPerDevPixel),
|
|
|
|
|
NSFloatPixelsToAppUnits(float(result.y), destAppUnitsPerDevPixel),
|
|
|
|
|
NSFloatPixelsToAppUnits(float(result.width), destAppUnitsPerDevPixel),
|
|
|
|
|
NSFloatPixelsToAppUnits(float(result.height), destAppUnitsPerDevPixel));
|
2011-12-28 07:24:18 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-04 23:21:03 +03:00
|
|
|
|
static LayoutDeviceIntPoint GetWidgetOffset(nsIWidget* aWidget, nsIWidget*& aRootWidget) {
|
|
|
|
|
LayoutDeviceIntPoint offset(0, 0);
|
2014-05-14 04:12:43 +04:00
|
|
|
|
while ((aWidget->WindowType() == eWindowType_child ||
|
2014-11-12 23:59:19 +03:00
|
|
|
|
aWidget->IsPlugin())) {
|
2014-05-14 04:12:43 +04:00
|
|
|
|
nsIWidget* parent = aWidget->GetParent();
|
|
|
|
|
if (!parent) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-01-15 06:27:09 +03:00
|
|
|
|
nsIntRect bounds;
|
2007-07-23 20:44:34 +04:00
|
|
|
|
aWidget->GetBounds(bounds);
|
2015-02-04 23:21:03 +03:00
|
|
|
|
offset += LayoutDeviceIntPoint::FromUntyped(bounds.TopLeft());
|
2007-07-23 20:44:34 +04:00
|
|
|
|
aWidget = parent;
|
|
|
|
|
}
|
|
|
|
|
aRootWidget = aWidget;
|
|
|
|
|
return offset;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-04 23:21:03 +03:00
|
|
|
|
static LayoutDeviceIntPoint
|
|
|
|
|
WidgetToWidgetOffset(nsIWidget* aFrom, nsIWidget* aTo) {
|
2014-11-04 17:52:16 +03:00
|
|
|
|
nsIWidget* fromRoot;
|
2015-02-04 23:21:03 +03:00
|
|
|
|
LayoutDeviceIntPoint fromOffset = GetWidgetOffset(aFrom, fromRoot);
|
2014-11-04 17:52:16 +03:00
|
|
|
|
nsIWidget* toRoot;
|
2015-02-04 23:21:03 +03:00
|
|
|
|
LayoutDeviceIntPoint toOffset = GetWidgetOffset(aTo, toRoot);
|
2014-11-04 17:52:16 +03:00
|
|
|
|
|
|
|
|
|
if (fromRoot == toRoot) {
|
|
|
|
|
return fromOffset - toOffset;
|
|
|
|
|
}
|
|
|
|
|
return aFrom->WidgetToScreenOffset() - aTo->WidgetToScreenOffset();
|
|
|
|
|
}
|
|
|
|
|
|
2005-08-23 07:57:07 +04:00
|
|
|
|
nsPoint
|
2010-04-27 20:15:01 +04:00
|
|
|
|
nsLayoutUtils::TranslateWidgetToView(nsPresContext* aPresContext,
|
2015-02-02 01:27:31 +03:00
|
|
|
|
nsIWidget* aWidget, const LayoutDeviceIntPoint& aPt,
|
2013-01-03 17:23:11 +04:00
|
|
|
|
nsView* aView)
|
2005-08-23 07:57:07 +04:00
|
|
|
|
{
|
2007-07-23 20:44:34 +04:00
|
|
|
|
nsPoint viewOffset;
|
|
|
|
|
nsIWidget* viewWidget = aView->GetNearestWidget(&viewOffset);
|
2010-08-19 05:16:58 +04:00
|
|
|
|
if (!viewWidget) {
|
|
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
|
}
|
2007-07-23 20:44:34 +04:00
|
|
|
|
|
2015-02-04 23:21:03 +03:00
|
|
|
|
LayoutDeviceIntPoint widgetPoint = aPt + WidgetToWidgetOffset(aWidget, viewWidget);
|
2007-07-23 20:44:34 +04:00
|
|
|
|
nsPoint widgetAppUnits(aPresContext->DevPixelsToAppUnits(widgetPoint.x),
|
|
|
|
|
aPresContext->DevPixelsToAppUnits(widgetPoint.y));
|
|
|
|
|
return widgetAppUnits - viewOffset;
|
2005-06-02 13:00:48 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-04 23:21:03 +03:00
|
|
|
|
LayoutDeviceIntPoint
|
2014-11-04 17:52:16 +03:00
|
|
|
|
nsLayoutUtils::TranslateViewToWidget(nsPresContext* aPresContext,
|
|
|
|
|
nsView* aView, nsPoint aPt,
|
|
|
|
|
nsIWidget* aWidget)
|
|
|
|
|
{
|
|
|
|
|
nsPoint viewOffset;
|
|
|
|
|
nsIWidget* viewWidget = aView->GetNearestWidget(&viewOffset);
|
|
|
|
|
if (!viewWidget) {
|
2015-02-04 23:21:03 +03:00
|
|
|
|
return LayoutDeviceIntPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
2014-11-04 17:52:16 +03:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-04 23:21:03 +03:00
|
|
|
|
LayoutDeviceIntPoint relativeToViewWidget(aPresContext->AppUnitsToDevPixels(aPt.x + viewOffset.x),
|
|
|
|
|
aPresContext->AppUnitsToDevPixels(aPt.y + viewOffset.y));
|
2014-11-04 17:52:16 +03:00
|
|
|
|
return relativeToViewWidget + WidgetToWidgetOffset(viewWidget, aWidget);
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-25 17:51:00 +03:00
|
|
|
|
// Combine aNewBreakType with aOrigBreakType, but limit the break types
|
2014-03-02 21:42:16 +04:00
|
|
|
|
// to NS_STYLE_CLEAR_LEFT, RIGHT, BOTH.
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint8_t
|
|
|
|
|
nsLayoutUtils::CombineBreakType(uint8_t aOrigBreakType,
|
|
|
|
|
uint8_t aNewBreakType)
|
2004-11-25 17:51:00 +03:00
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint8_t breakType = aOrigBreakType;
|
2004-11-25 17:51:00 +03:00
|
|
|
|
switch(breakType) {
|
|
|
|
|
case NS_STYLE_CLEAR_LEFT:
|
2014-03-02 21:42:16 +04:00
|
|
|
|
if (NS_STYLE_CLEAR_RIGHT == aNewBreakType ||
|
|
|
|
|
NS_STYLE_CLEAR_BOTH == aNewBreakType) {
|
|
|
|
|
breakType = NS_STYLE_CLEAR_BOTH;
|
2004-11-25 17:51:00 +03:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case NS_STYLE_CLEAR_RIGHT:
|
2014-03-02 21:42:16 +04:00
|
|
|
|
if (NS_STYLE_CLEAR_LEFT == aNewBreakType ||
|
|
|
|
|
NS_STYLE_CLEAR_BOTH == aNewBreakType) {
|
|
|
|
|
breakType = NS_STYLE_CLEAR_BOTH;
|
2004-11-25 17:51:00 +03:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case NS_STYLE_CLEAR_NONE:
|
2014-03-02 21:42:16 +04:00
|
|
|
|
if (NS_STYLE_CLEAR_LEFT == aNewBreakType ||
|
|
|
|
|
NS_STYLE_CLEAR_RIGHT == aNewBreakType ||
|
|
|
|
|
NS_STYLE_CLEAR_BOTH == aNewBreakType) {
|
2004-11-25 17:51:00 +03:00
|
|
|
|
breakType = aNewBreakType;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return breakType;
|
|
|
|
|
}
|
2005-02-08 05:15:26 +03:00
|
|
|
|
|
2011-11-17 07:44:16 +04:00
|
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
2006-01-26 05:29:17 +03:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2012-04-09 21:44:32 +04:00
|
|
|
|
static bool gDumpEventList = false;
|
2012-03-01 12:26:09 +04:00
|
|
|
|
int gPaintCount = 0;
|
2006-01-26 05:29:17 +03:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
nsIFrame*
|
2013-07-26 06:31:41 +04:00
|
|
|
|
nsLayoutUtils::GetFrameForPoint(nsIFrame* aFrame, nsPoint aPt, uint32_t aFlags)
|
2010-04-08 04:31:26 +04:00
|
|
|
|
{
|
2014-05-24 01:12:29 +04:00
|
|
|
|
PROFILER_LABEL("nsLayoutUtils", "GetFrameForPoint",
|
|
|
|
|
js::ProfileEntry::Category::GRAPHICS);
|
|
|
|
|
|
2010-04-08 04:31:26 +04:00
|
|
|
|
nsresult rv;
|
2011-09-09 01:29:54 +04:00
|
|
|
|
nsAutoTArray<nsIFrame*,8> outFrames;
|
2013-07-26 06:31:41 +04:00
|
|
|
|
rv = GetFramesForArea(aFrame, nsRect(aPt, nsSize(1, 1)), outFrames, aFlags);
|
2012-07-30 18:20:58 +04:00
|
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
|
|
|
|
return outFrames.Length() ? outFrames.ElementAt(0) : nullptr;
|
2010-04-08 04:31:26 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
|
nsLayoutUtils::GetFramesForArea(nsIFrame* aFrame, const nsRect& aRect,
|
|
|
|
|
nsTArray<nsIFrame*> &aOutFrames,
|
2013-07-26 06:31:41 +04:00
|
|
|
|
uint32_t aFlags)
|
2006-01-26 05:29:17 +03:00
|
|
|
|
{
|
2014-05-24 01:12:29 +04:00
|
|
|
|
PROFILER_LABEL("nsLayoutUtils", "GetFramesForArea",
|
|
|
|
|
js::ProfileEntry::Category::GRAPHICS);
|
|
|
|
|
|
2010-11-08 12:06:14 +03:00
|
|
|
|
nsDisplayListBuilder builder(aFrame, nsDisplayListBuilder::EVENT_DELIVERY,
|
2013-07-26 06:31:41 +04:00
|
|
|
|
false);
|
2006-01-26 05:29:17 +03:00
|
|
|
|
nsDisplayList list;
|
2006-04-18 03:16:46 +04:00
|
|
|
|
|
2013-07-26 06:31:41 +04:00
|
|
|
|
if (aFlags & IGNORE_PAINT_SUPPRESSION) {
|
2007-08-30 00:38:44 +04:00
|
|
|
|
builder.IgnorePaintSuppression();
|
2010-04-08 04:31:26 +04:00
|
|
|
|
}
|
2008-10-27 23:16:23 +03:00
|
|
|
|
|
2013-07-26 06:31:41 +04:00
|
|
|
|
if (aFlags & IGNORE_ROOT_SCROLL_FRAME) {
|
2012-04-09 21:44:32 +04:00
|
|
|
|
nsIFrame* rootScrollFrame =
|
|
|
|
|
aFrame->PresContext()->PresShell()->GetRootScrollFrame();
|
2008-10-27 23:16:23 +03:00
|
|
|
|
if (rootScrollFrame) {
|
|
|
|
|
builder.SetIgnoreScrollFrame(rootScrollFrame);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-18 09:37:24 +04:00
|
|
|
|
if (aFlags & IGNORE_CROSS_DOC) {
|
|
|
|
|
builder.SetDescendIntoSubdocuments(false);
|
|
|
|
|
}
|
2008-10-27 23:16:23 +03:00
|
|
|
|
|
2014-09-06 08:16:34 +04:00
|
|
|
|
builder.EnterPresShell(aFrame);
|
|
|
|
|
aFrame->BuildDisplayListForStackingContext(&builder, aRect, &list);
|
|
|
|
|
builder.LeavePresShell(aFrame);
|
2006-01-26 05:29:17 +03:00
|
|
|
|
|
2011-11-17 07:44:16 +04:00
|
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
2006-01-26 05:29:17 +03:00
|
|
|
|
if (gDumpEventList) {
|
2013-11-24 02:44:18 +04:00
|
|
|
|
fprintf_stderr(stderr, "Event handling --- (%d,%d):\n", aRect.x, aRect.y);
|
2014-06-20 02:36:25 +04:00
|
|
|
|
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
nsFrame::PrintDisplayList(&builder, list, ss);
|
2014-08-02 14:03:00 +04:00
|
|
|
|
print_stderr(ss);
|
2006-01-26 05:29:17 +03:00
|
|
|
|
}
|
|
|
|
|
#endif
|
2009-08-21 01:52:48 +04:00
|
|
|
|
|
2008-01-04 05:08:29 +03:00
|
|
|
|
nsDisplayItem::HitTestState hitTestState;
|
2014-09-06 08:16:34 +04:00
|
|
|
|
list.HitTest(&builder, aRect, &hitTestState, &aOutFrames);
|
2006-01-26 05:29:17 +03:00
|
|
|
|
list.DeleteAll();
|
2010-04-08 04:31:26 +04:00
|
|
|
|
return NS_OK;
|
2006-01-26 05:29:17 +03:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-22 05:36:25 +03:00
|
|
|
|
// aScrollFrameAsScrollable must be non-nullptr and queryable to an nsIFrame
|
2015-07-27 21:06:05 +03:00
|
|
|
|
FrameMetrics
|
|
|
|
|
nsLayoutUtils::CalculateBasicFrameMetrics(nsIScrollableFrame* aScrollFrame) {
|
2014-11-22 05:36:25 +03:00
|
|
|
|
nsIFrame* frame = do_QueryFrame(aScrollFrame);
|
|
|
|
|
MOZ_ASSERT(frame);
|
|
|
|
|
|
2014-03-19 21:15:54 +04:00
|
|
|
|
// Calculate the metrics necessary for calculating the displayport.
|
2014-09-26 19:29:38 +04:00
|
|
|
|
// This code has a lot in common with the code in ComputeFrameMetrics();
|
2014-03-19 21:15:54 +04:00
|
|
|
|
// we may want to refactor this at some point.
|
|
|
|
|
FrameMetrics metrics;
|
2014-11-22 05:36:25 +03:00
|
|
|
|
nsPresContext* presContext = frame->PresContext();
|
2014-03-19 21:15:54 +04:00
|
|
|
|
nsIPresShell* presShell = presContext->PresShell();
|
|
|
|
|
CSSToLayoutDeviceScale deviceScale(float(nsPresContext::AppUnitsPerCSSPixel())
|
|
|
|
|
/ presContext->AppUnitsPerDevPixel());
|
2014-11-10 22:35:11 +03:00
|
|
|
|
float resolution = 1.0f;
|
2014-11-22 05:36:25 +03:00
|
|
|
|
if (frame == presShell->GetRootScrollFrame()) {
|
2014-07-03 23:22:22 +04:00
|
|
|
|
// Only the root scrollable frame for a given presShell should pick up
|
|
|
|
|
// the presShell's resolution. All the other frames are 1.0.
|
2015-03-07 02:07:59 +03:00
|
|
|
|
resolution = presShell->GetResolution();
|
2014-07-03 23:22:22 +04:00
|
|
|
|
}
|
2014-10-24 23:49:38 +04:00
|
|
|
|
// Note: unlike in ComputeFrameMetrics(), we don't know the full cumulative
|
|
|
|
|
// resolution including FrameMetrics::mExtraResolution, because layout hasn't
|
|
|
|
|
// chosen a resolution to paint at yet. However, the display port calculation
|
|
|
|
|
// divides out mExtraResolution anyways, so we get the correct result by
|
|
|
|
|
// setting the mCumulativeResolution to everything except the extra resolution
|
|
|
|
|
// and leaving mExtraResolution at 1.
|
2015-03-06 21:54:10 +03:00
|
|
|
|
LayoutDeviceToLayerScale2D cumulativeResolution(
|
|
|
|
|
presShell->GetCumulativeResolution()
|
|
|
|
|
* nsLayoutUtils::GetTransformToAncestorScale(frame));
|
2014-03-19 21:15:54 +04:00
|
|
|
|
|
2014-11-10 22:35:11 +03:00
|
|
|
|
LayerToParentLayerScale layerToParentLayerScale(1.0f);
|
2014-12-18 01:14:05 +03:00
|
|
|
|
metrics.SetDevPixelsPerCSSPixel(deviceScale);
|
2015-01-17 00:15:52 +03:00
|
|
|
|
metrics.SetPresShellResolution(resolution);
|
2014-12-19 03:33:18 +03:00
|
|
|
|
metrics.SetCumulativeResolution(cumulativeResolution);
|
2014-11-10 22:35:11 +03:00
|
|
|
|
metrics.SetZoom(deviceScale * cumulativeResolution * layerToParentLayerScale);
|
2014-03-19 21:15:54 +04:00
|
|
|
|
|
|
|
|
|
// Only the size of the composition bounds is relevant to the
|
|
|
|
|
// displayport calculation, not its origin.
|
2014-11-22 05:36:25 +03:00
|
|
|
|
nsSize compositionSize = nsLayoutUtils::CalculateCompositionSizeForFrame(frame);
|
2015-03-06 21:54:10 +03:00
|
|
|
|
LayoutDeviceToParentLayerScale2D compBoundsScale;
|
2014-11-22 05:36:25 +03:00
|
|
|
|
if (frame == presShell->GetRootScrollFrame() && presContext->IsRootContentDocument()) {
|
2014-10-20 23:53:29 +04:00
|
|
|
|
if (presContext->GetParentPresContext()) {
|
2015-03-07 02:07:59 +03:00
|
|
|
|
float res = presContext->GetParentPresContext()->PresShell()->GetCumulativeResolution();
|
|
|
|
|
compBoundsScale = LayoutDeviceToParentLayerScale2D(
|
|
|
|
|
LayoutDeviceToParentLayerScale(res));
|
2014-10-20 23:53:29 +04:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2014-11-10 22:35:11 +03:00
|
|
|
|
compBoundsScale = cumulativeResolution * layerToParentLayerScale;
|
2014-10-20 23:53:29 +04:00
|
|
|
|
}
|
2015-05-07 21:44:03 +03:00
|
|
|
|
metrics.SetCompositionBounds(
|
|
|
|
|
LayoutDeviceRect::FromAppUnits(nsRect(nsPoint(0, 0), compositionSize),
|
2014-07-04 16:12:41 +04:00
|
|
|
|
presContext->AppUnitsPerDevPixel())
|
2015-05-07 21:44:03 +03:00
|
|
|
|
* compBoundsScale);
|
2014-03-19 21:15:54 +04:00
|
|
|
|
|
|
|
|
|
metrics.SetRootCompositionSize(
|
2014-11-22 05:36:25 +03:00
|
|
|
|
nsLayoutUtils::CalculateRootCompositionSize(frame, false, metrics));
|
2014-03-19 21:15:54 +04:00
|
|
|
|
|
|
|
|
|
metrics.SetScrollOffset(CSSPoint::FromAppUnits(
|
2014-11-22 05:36:25 +03:00
|
|
|
|
aScrollFrame->GetScrollPosition()));
|
2014-03-19 21:15:54 +04:00
|
|
|
|
|
2014-12-27 20:48:27 +03:00
|
|
|
|
metrics.SetScrollableRect(CSSRect::FromAppUnits(
|
|
|
|
|
nsLayoutUtils::CalculateScrollableRectForFrame(aScrollFrame, nullptr)));
|
2014-03-19 21:15:54 +04:00
|
|
|
|
|
|
|
|
|
return metrics;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-22 05:36:25 +03:00
|
|
|
|
bool
|
|
|
|
|
nsLayoutUtils::CalculateAndSetDisplayPortMargins(nsIScrollableFrame* aScrollFrame,
|
|
|
|
|
RepaintMode aRepaintMode) {
|
|
|
|
|
nsIFrame* frame = do_QueryFrame(aScrollFrame);
|
|
|
|
|
MOZ_ASSERT(frame);
|
|
|
|
|
nsIContent* content = frame->GetContent();
|
|
|
|
|
MOZ_ASSERT(content);
|
|
|
|
|
|
2015-07-27 21:06:05 +03:00
|
|
|
|
FrameMetrics metrics = CalculateBasicFrameMetrics(aScrollFrame);
|
2014-11-22 05:36:25 +03:00
|
|
|
|
ScreenMargin displayportMargins = APZCTreeManager::CalculatePendingDisplayPort(
|
|
|
|
|
metrics, ParentLayerPoint(0.0f, 0.0f), 0.0);
|
|
|
|
|
nsIPresShell* presShell = frame->PresContext()->GetPresShell();
|
|
|
|
|
return nsLayoutUtils::SetDisplayPortMargins(
|
|
|
|
|
content, presShell, displayportMargins, 0, aRepaintMode);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-19 21:29:24 +04:00
|
|
|
|
bool
|
|
|
|
|
nsLayoutUtils::GetOrMaybeCreateDisplayPort(nsDisplayListBuilder& aBuilder,
|
|
|
|
|
nsIFrame* aScrollFrame,
|
|
|
|
|
nsRect aDisplayPortBase,
|
|
|
|
|
nsRect* aOutDisplayport) {
|
|
|
|
|
nsIContent* content = aScrollFrame->GetContent();
|
|
|
|
|
nsIScrollableFrame* scrollableFrame = do_QueryFrame(aScrollFrame);
|
|
|
|
|
if (!content || !scrollableFrame) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set the base rect. Note that this will not influence 'haveDisplayPort',
|
|
|
|
|
// which is based on either the whole rect or margins being set, but it
|
|
|
|
|
// will affect what is returned in 'aOutDisplayPort' if margins are set.
|
|
|
|
|
SetDisplayPortBase(content, aDisplayPortBase);
|
|
|
|
|
|
|
|
|
|
bool haveDisplayPort = GetDisplayPort(content, aOutDisplayport);
|
|
|
|
|
|
2014-10-14 22:51:34 +04:00
|
|
|
|
// We perform an optimization where we ensure that at least one
|
2014-03-19 21:29:24 +04:00
|
|
|
|
// async-scrollable frame (i.e. one that WantsAsyncScroll()) has a displayport.
|
|
|
|
|
// If that's not the case yet, and we are async-scrollable, we will get a
|
|
|
|
|
// displayport.
|
|
|
|
|
// Note: we only do this in processes where we do subframe scrolling to
|
|
|
|
|
// begin with (i.e., not in the parent process on B2G).
|
2015-02-04 02:02:04 +03:00
|
|
|
|
if (aBuilder.IsPaintingToWindow() &&
|
2015-06-04 23:51:10 +03:00
|
|
|
|
nsLayoutUtils::AsyncPanZoomEnabled(aScrollFrame) &&
|
2014-03-19 21:29:24 +04:00
|
|
|
|
!aBuilder.HaveScrollableDisplayPort() &&
|
|
|
|
|
scrollableFrame->WantAsyncScroll()) {
|
|
|
|
|
|
|
|
|
|
// If we don't already have a displayport, calculate and set one.
|
|
|
|
|
if (!haveDisplayPort) {
|
2014-11-22 05:36:25 +03:00
|
|
|
|
CalculateAndSetDisplayPortMargins(scrollableFrame, nsLayoutUtils::RepaintMode::DoNotRepaint);
|
2014-03-19 21:29:24 +04:00
|
|
|
|
haveDisplayPort = GetDisplayPort(content, aOutDisplayport);
|
|
|
|
|
NS_ASSERTION(haveDisplayPort, "should have a displayport after having just set it");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Record that the we now have a scrollable display port.
|
|
|
|
|
aBuilder.SetHaveScrollableDisplayPort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return haveDisplayPort;
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
|
nsresult
|
2011-04-08 05:04:40 +04:00
|
|
|
|
nsLayoutUtils::PaintFrame(nsRenderingContext* aRenderingContext, nsIFrame* aFrame,
|
2009-07-22 04:45:14 +04:00
|
|
|
|
const nsRegion& aDirtyRegion, nscolor aBackstop,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t aFlags)
|
2006-01-26 05:29:17 +03:00
|
|
|
|
{
|
2014-05-24 01:12:29 +04:00
|
|
|
|
PROFILER_LABEL("nsLayoutUtils", "PaintFrame",
|
|
|
|
|
js::ProfileEntry::Category::GRAPHICS);
|
|
|
|
|
|
2010-08-08 22:49:07 +04:00
|
|
|
|
if (aFlags & PAINT_WIDGET_LAYERS) {
|
2013-01-03 17:23:11 +04:00
|
|
|
|
nsView* view = aFrame->GetView();
|
2010-08-22 04:55:55 +04:00
|
|
|
|
if (!(view && view->GetWidget() && GetDisplayRootFrame(aFrame) == aFrame)) {
|
|
|
|
|
aFlags &= ~PAINT_WIDGET_LAYERS;
|
|
|
|
|
NS_ASSERTION(aRenderingContext, "need a rendering context");
|
|
|
|
|
}
|
2010-08-08 22:49:07 +04:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-16 01:07:51 +04:00
|
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
2010-07-16 01:07:52 +04:00
|
|
|
|
nsIPresShell* presShell = presContext->PresShell();
|
2012-10-06 17:03:23 +04:00
|
|
|
|
nsRootPresContext* rootPresContext = presContext->GetRootPresContext();
|
|
|
|
|
if (!rootPresContext) {
|
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
2010-07-16 01:07:51 +04:00
|
|
|
|
|
2014-12-08 23:43:16 +03:00
|
|
|
|
TimeStamp startBuildDisplayList = TimeStamp::Now();
|
2014-03-19 21:29:24 +04:00
|
|
|
|
nsDisplayListBuilder builder(aFrame, nsDisplayListBuilder::PAINTING,
|
|
|
|
|
!(aFlags & PAINT_HIDE_CARET));
|
2015-04-15 22:48:09 +03:00
|
|
|
|
if (aFlags & PAINT_IN_TRANSFORM) {
|
|
|
|
|
builder.SetInTransform(true);
|
|
|
|
|
}
|
|
|
|
|
if (aFlags & PAINT_SYNC_DECODE_IMAGES) {
|
|
|
|
|
builder.SetSyncDecodeImages(true);
|
|
|
|
|
}
|
|
|
|
|
if (aFlags & (PAINT_WIDGET_LAYERS | PAINT_TO_WINDOW)) {
|
|
|
|
|
builder.SetPaintingToWindow(true);
|
|
|
|
|
}
|
|
|
|
|
if (aFlags & PAINT_IGNORE_SUPPRESSION) {
|
|
|
|
|
builder.IgnorePaintSuppression();
|
|
|
|
|
}
|
2014-03-19 21:29:24 +04:00
|
|
|
|
|
2011-03-16 02:20:19 +03:00
|
|
|
|
nsIFrame* rootScrollFrame = presShell->GetRootScrollFrame();
|
|
|
|
|
bool usingDisplayPort = false;
|
|
|
|
|
nsRect displayport;
|
2014-10-21 01:32:11 +04:00
|
|
|
|
if (rootScrollFrame && !aFrame->GetParent() &&
|
2015-04-16 00:14:32 +03:00
|
|
|
|
(aFlags & (PAINT_WIDGET_LAYERS | PAINT_TO_WINDOW)) &&
|
|
|
|
|
gfxPrefs::LayoutUseContainersForRootFrames()) {
|
2014-03-19 21:29:24 +04:00
|
|
|
|
nsRect displayportBase(
|
|
|
|
|
nsPoint(0,0),
|
|
|
|
|
nsLayoutUtils::CalculateCompositionSizeForFrame(rootScrollFrame));
|
|
|
|
|
usingDisplayPort = nsLayoutUtils::GetOrMaybeCreateDisplayPort(
|
|
|
|
|
builder, rootScrollFrame, displayportBase, &displayport);
|
2011-03-16 02:20:19 +03:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-16 01:07:51 +04:00
|
|
|
|
nsRegion visibleRegion;
|
2010-09-04 00:10:46 +04:00
|
|
|
|
if (aFlags & PAINT_WIDGET_LAYERS) {
|
2010-07-16 01:07:51 +04:00
|
|
|
|
// This layer tree will be reused, so we'll need to calculate it
|
2010-09-04 00:10:46 +04:00
|
|
|
|
// for the whole "visible" area of the window
|
2014-12-08 23:43:16 +03:00
|
|
|
|
//
|
2010-09-04 00:10:46 +04:00
|
|
|
|
// |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-16 02:20:19 +03:00
|
|
|
|
if (!usingDisplayPort) {
|
2010-10-07 08:25:47 +04:00
|
|
|
|
visibleRegion = aFrame->GetVisualOverflowRectRelativeToSelf();
|
2010-09-04 00:10:46 +04:00
|
|
|
|
} else {
|
2011-03-16 02:20:19 +03:00
|
|
|
|
visibleRegion = displayport;
|
2010-09-04 00:10:46 +04:00
|
|
|
|
}
|
2010-07-16 01:07:51 +04:00
|
|
|
|
} else {
|
|
|
|
|
visibleRegion = aDirtyRegion;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-20 07:49:16 +04: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-29 10:19:26 +04:00
|
|
|
|
bool willFlushRetainedLayers = (aFlags & PAINT_HIDE_CARET) != 0;
|
2010-08-20 07:49:16 +04:00
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
|
nsDisplayList list;
|
2015-03-02 14:01:58 +03:00
|
|
|
|
|
|
|
|
|
// If the root has embedded plugins, flag the builder so we know we'll need
|
|
|
|
|
// to update plugin geometry after painting.
|
2012-10-06 17:03:23 +04:00
|
|
|
|
if ((aFlags & PAINT_WIDGET_LAYERS) &&
|
|
|
|
|
!willFlushRetainedLayers &&
|
|
|
|
|
!(aFlags & PAINT_DOCUMENT_RELATIVE) &&
|
|
|
|
|
rootPresContext->NeedToComputePluginGeometryUpdates()) {
|
|
|
|
|
builder.SetWillComputePluginGeometry(true);
|
|
|
|
|
}
|
2011-02-18 03:33:31 +03:00
|
|
|
|
|
2015-03-02 14:01:58 +03:00
|
|
|
|
nsRect canvasArea(nsPoint(0, 0), aFrame->GetSize());
|
2014-02-28 02:01:53 +04:00
|
|
|
|
bool ignoreViewportScrolling =
|
|
|
|
|
aFrame->GetParent() ? false : presShell->IgnoringViewportScrolling();
|
2013-08-29 07:38:15 +04:00
|
|
|
|
if (ignoreViewportScrolling && rootScrollFrame) {
|
2013-08-29 07:37:42 +04:00
|
|
|
|
nsIScrollableFrame* rootScrollableFrame =
|
|
|
|
|
presShell->GetRootScrollFrameAsScrollable();
|
|
|
|
|
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);
|
|
|
|
|
if (aRenderingContext) {
|
2014-09-11 10:48:10 +04:00
|
|
|
|
gfxPoint devPixelOffset =
|
|
|
|
|
nsLayoutUtils::PointToGfxPoint(pos,
|
|
|
|
|
presContext->AppUnitsPerDevPixel());
|
|
|
|
|
aRenderingContext->ThebesContext()->SetMatrix(
|
|
|
|
|
aRenderingContext->ThebesContext()->CurrentMatrix().Translate(devPixelOffset));
|
2010-07-16 01:07:52 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-29 07:37:42 +04: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));
|
|
|
|
|
}
|
2010-07-16 01:07:52 +04:00
|
|
|
|
}
|
2009-07-04 13:30:59 +04:00
|
|
|
|
|
2014-09-06 08:16:34 +04:00
|
|
|
|
builder.EnterPresShell(aFrame);
|
2010-07-16 01:07:51 +04:00
|
|
|
|
nsRect dirtyRect = visibleRegion.GetBounds();
|
2012-04-16 22:37:59 +04:00
|
|
|
|
{
|
2014-04-30 17:00:45 +04:00
|
|
|
|
// If a scrollable container layer is created in nsDisplayList::PaintForFrame,
|
|
|
|
|
// it will be the scroll parent for display items that are built in the
|
|
|
|
|
// BuildDisplayListForStackingContext call below. We need to set the scroll
|
|
|
|
|
// parent on the display list builder while we build those items, so that they
|
|
|
|
|
// can pick up their scroll parent's id.
|
|
|
|
|
ViewID id = FrameMetrics::NULL_SCROLL_ID;
|
|
|
|
|
if (ignoreViewportScrolling && presContext->IsRootContentDocument()) {
|
|
|
|
|
if (nsIFrame* rootScrollFrame = presShell->GetRootScrollFrame()) {
|
|
|
|
|
if (nsIContent* content = rootScrollFrame->GetContent()) {
|
|
|
|
|
id = nsLayoutUtils::FindOrCreateIDFor(content);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-04-30 13:06:00 +03:00
|
|
|
|
#if !defined(MOZ_WIDGET_ANDROID) || defined(MOZ_ANDROID_APZ)
|
2015-05-04 21:37:22 +03:00
|
|
|
|
else if (presShell->GetDocument() && presShell->GetDocument()->IsRootDisplayDocument()
|
|
|
|
|
&& !presShell->GetRootScrollFrame()) {
|
2015-04-30 13:06:00 +03:00
|
|
|
|
// In cases where the root document is a XUL document, we want to take
|
|
|
|
|
// the ViewID from the root element, as that will be the ViewID of the
|
2015-05-04 21:37:22 +03:00
|
|
|
|
// root APZC in the tree. Skip doing this in cases where we know
|
|
|
|
|
// nsGfxScrollFrame::BuilDisplayList will do it instead.
|
2015-04-30 13:06:00 +03:00
|
|
|
|
if (dom::Element* element = presShell->GetDocument()->GetDocumentElement()) {
|
|
|
|
|
id = nsLayoutUtils::FindOrCreateIDFor(element);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-04-30 17:00:45 +04:00
|
|
|
|
nsDisplayListBuilder::AutoCurrentScrollParentIdSetter idSetter(&builder, id);
|
|
|
|
|
|
2014-05-24 01:12:29 +04:00
|
|
|
|
PROFILER_LABEL("nsLayoutUtils", "PaintFrame::BuildDisplayList",
|
|
|
|
|
js::ProfileEntry::Category::GRAPHICS);
|
|
|
|
|
|
2013-02-14 15:08:08 +04:00
|
|
|
|
aFrame->BuildDisplayListForStackingContext(&builder, dirtyRect, &list);
|
2012-04-16 22:37:59 +04:00
|
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
|
const bool paintAllContinuations = aFlags & PAINT_ALL_CONTINUATIONS;
|
2010-08-13 17:32:04 +04:00
|
|
|
|
NS_ASSERTION(!paintAllContinuations || !aFrame->GetPrevContinuation(),
|
|
|
|
|
"If painting all continuations, the frame must be "
|
|
|
|
|
"first-continuation");
|
|
|
|
|
|
2010-08-08 22:49:07 +04:00
|
|
|
|
nsIAtom* frameType = aFrame->GetType();
|
2006-04-18 03:16:46 +04:00
|
|
|
|
|
2010-08-13 17:32:04 +04:00
|
|
|
|
if (paintAllContinuations) {
|
|
|
|
|
nsIFrame* currentFrame = aFrame;
|
2013-02-14 15:08:08 +04:00
|
|
|
|
while ((currentFrame = currentFrame->GetNextContinuation()) != nullptr) {
|
2014-05-24 01:12:29 +04:00
|
|
|
|
PROFILER_LABEL("nsLayoutUtils", "PaintFrame::ContinuationsBuildDisplayList",
|
|
|
|
|
js::ProfileEntry::Category::GRAPHICS);
|
|
|
|
|
|
2010-08-13 17:32:04 +04:00
|
|
|
|
nsRect frameDirty = dirtyRect - builder.ToReferenceFrame(currentFrame);
|
2013-02-14 15:08:08 +04:00
|
|
|
|
currentFrame->BuildDisplayListForStackingContext(&builder,
|
|
|
|
|
frameDirty, &list);
|
2010-08-13 17:32:04 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-30 02:10:50 +04: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 22:49:07 +04:00
|
|
|
|
if (frameType == nsGkAtoms::viewportFrame &&
|
|
|
|
|
nsLayoutUtils::NeedsPrintPreviewBackground(presContext)) {
|
2009-07-30 02:10:50 +04:00
|
|
|
|
nsRect bounds = nsRect(builder.ToReferenceFrame(aFrame),
|
|
|
|
|
aFrame->GetSize());
|
2014-09-06 08:16:34 +04:00
|
|
|
|
nsDisplayListBuilder::AutoBuildingDisplayList
|
|
|
|
|
buildingDisplayList(&builder, aFrame, bounds, false);
|
2013-02-14 15:08:08 +04:00
|
|
|
|
presShell->AddPrintPreviewBackgroundItem(builder, list, aFrame, bounds);
|
2009-07-30 02:10:50 +04: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-16 01:07:53 +04: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 23:28:20 +04:00
|
|
|
|
canvasArea.IntersectRect(canvasArea, visibleRegion.GetBounds());
|
2014-09-06 08:16:34 +04:00
|
|
|
|
nsDisplayListBuilder::AutoBuildingDisplayList
|
|
|
|
|
buildingDisplayList(&builder, aFrame, canvasArea, false);
|
2013-02-14 15:08:08 +04:00
|
|
|
|
presShell->AddCanvasBackgroundColorItem(
|
2010-07-16 01:07:52 +04:00
|
|
|
|
builder, list, aFrame, canvasArea, aBackstop);
|
2010-08-08 22:49:07 +04:00
|
|
|
|
|
|
|
|
|
// If the passed in backstop color makes us draw something different from
|
|
|
|
|
// normal, we need to flush layers.
|
2010-09-04 00:10:46 +04:00
|
|
|
|
if ((aFlags & PAINT_WIDGET_LAYERS) && !willFlushRetainedLayers) {
|
2013-01-03 17:23:11 +04:00
|
|
|
|
nsView* view = aFrame->GetView();
|
2010-08-08 22:49:07 +04:00
|
|
|
|
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 18:59:28 +04:00
|
|
|
|
willFlushRetainedLayers = true;
|
2010-08-08 22:49:07 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-07-04 13:30:59 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-06 08:16:34 +04:00
|
|
|
|
builder.LeavePresShell(aFrame);
|
2014-12-08 23:43:16 +03:00
|
|
|
|
Telemetry::AccumulateTimeDelta(Telemetry::PAINT_BUILD_DISPLAYLIST_TIME,
|
|
|
|
|
startBuildDisplayList);
|
2006-01-26 05:29:17 +03:00
|
|
|
|
|
2010-09-02 00:44:48 +04:00
|
|
|
|
if (builder.GetHadToIgnorePaintSuppression()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
|
willFlushRetainedLayers = true;
|
2010-09-02 00:44:48 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-20 02:36:25 +04:00
|
|
|
|
|
2014-12-18 21:32:53 +03:00
|
|
|
|
bool profilerNeedsDisplayList = profiler_feature_active("displaylistdump");
|
2014-12-31 23:17:39 +03:00
|
|
|
|
bool consoleNeedsDisplayList = gfxUtils::DumpDisplayList() || gfxUtils::sDumpPainting;
|
|
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
|
|
|
|
FILE* savedDumpFile = gfxUtils::sDumpPaintFile;
|
|
|
|
|
#endif
|
2014-12-18 21:32:53 +03:00
|
|
|
|
|
2014-12-31 23:17:39 +03:00
|
|
|
|
UniquePtr<std::stringstream> ss;
|
2014-12-18 21:32:53 +03:00
|
|
|
|
if (consoleNeedsDisplayList || profilerNeedsDisplayList) {
|
2014-12-31 23:17:39 +03:00
|
|
|
|
ss = MakeUnique<std::stringstream>();
|
|
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
2012-03-01 12:26:09 +04:00
|
|
|
|
if (gfxUtils::sDumpPaintingToFile) {
|
|
|
|
|
nsCString string("dump-");
|
|
|
|
|
string.AppendInt(gPaintCount);
|
2014-05-22 07:48:51 +04:00
|
|
|
|
string.AppendLiteral(".html");
|
2012-03-01 12:26:09 +04:00
|
|
|
|
gfxUtils::sDumpPaintFile = fopen(string.BeginReading(), "w");
|
|
|
|
|
} else {
|
2013-11-24 02:44:18 +04:00
|
|
|
|
gfxUtils::sDumpPaintFile = stderr;
|
2012-03-01 12:26:09 +04:00
|
|
|
|
}
|
2012-08-07 21:57:26 +04:00
|
|
|
|
if (gfxUtils::sDumpPaintingToFile) {
|
2014-10-21 01:32:10 +04:00
|
|
|
|
*ss << "<html><head><script>var array = {}; function ViewImage(index) { window.location = array[index]; }</script></head><body>";
|
2012-08-07 21:57:26 +04:00
|
|
|
|
}
|
2014-12-31 23:17:39 +03:00
|
|
|
|
#endif
|
2014-10-21 01:32:10 +04:00
|
|
|
|
*ss << nsPrintfCString("Painting --- before optimization (dirty %d,%d,%d,%d):\n",
|
2014-06-20 02:36:25 +04:00
|
|
|
|
dirtyRect.x, dirtyRect.y, dirtyRect.width, dirtyRect.height).get();
|
2014-10-21 01:32:10 +04:00
|
|
|
|
nsFrame::PrintDisplayList(&builder, list, *ss, gfxUtils::sDumpPaintingToFile);
|
2012-03-01 12:26:09 +04:00
|
|
|
|
if (gfxUtils::sDumpPaintingToFile) {
|
2014-10-21 01:32:10 +04:00
|
|
|
|
*ss << "<script>";
|
|
|
|
|
} else {
|
|
|
|
|
// Flush stream now to avoid reordering dump output relative to
|
|
|
|
|
// messages dumped by PaintRoot below.
|
2014-12-18 21:32:53 +03:00
|
|
|
|
if (profilerNeedsDisplayList && !consoleNeedsDisplayList) {
|
|
|
|
|
profiler_log(ss->str().c_str());
|
|
|
|
|
} else {
|
|
|
|
|
// Send to the console which will send to the profiler if required.
|
|
|
|
|
fprint_stderr(gfxUtils::sDumpPaintFile, *ss);
|
|
|
|
|
}
|
2014-10-21 01:32:10 +04:00
|
|
|
|
ss = MakeUnique<std::stringstream>();
|
2012-03-01 12:26:09 +04:00
|
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
|
}
|
2009-08-21 01:52:48 +04:00
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t flags = nsDisplayList::PAINT_DEFAULT;
|
2010-03-01 11:03:49 +03:00
|
|
|
|
if (aFlags & PAINT_WIDGET_LAYERS) {
|
|
|
|
|
flags |= nsDisplayList::PAINT_USE_WIDGET_LAYERS;
|
2010-09-04 00:10:46 +04: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-16 01:07:52 +04:00
|
|
|
|
flags |= nsDisplayList::PAINT_FLUSH_LAYERS;
|
2011-02-18 00:42:39 +03:00
|
|
|
|
} else if (!(aFlags & PAINT_DOCUMENT_RELATIVE)) {
|
2011-03-25 18:03:35 +03:00
|
|
|
|
nsIWidget *widget = aFrame->GetNearestWidget();
|
|
|
|
|
if (widget) {
|
2011-02-18 00:42:39 +03:00
|
|
|
|
// 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 18:03:35 +03:00
|
|
|
|
widget->UpdateThemeGeometries(builder.GetThemeGeometries());
|
2011-02-18 00:42:39 +03:00
|
|
|
|
}
|
2010-07-16 01:07:52 +04:00
|
|
|
|
}
|
2010-03-01 11:03:49 +03:00
|
|
|
|
}
|
2011-01-19 11:27:54 +03:00
|
|
|
|
if (aFlags & PAINT_EXISTING_TRANSACTION) {
|
|
|
|
|
flags |= nsDisplayList::PAINT_EXISTING_TRANSACTION;
|
|
|
|
|
}
|
2012-08-13 14:10:10 +04:00
|
|
|
|
if (aFlags & PAINT_NO_COMPOSITE) {
|
|
|
|
|
flags |= nsDisplayList::PAINT_NO_COMPOSITE;
|
|
|
|
|
}
|
2014-01-30 09:41:17 +04:00
|
|
|
|
if (aFlags & PAINT_COMPRESSED) {
|
|
|
|
|
flags |= nsDisplayList::PAINT_COMPRESSED;
|
|
|
|
|
}
|
2010-07-16 01:07:51 +04:00
|
|
|
|
|
2014-12-08 23:43:16 +03:00
|
|
|
|
TimeStamp paintStart = TimeStamp::Now();
|
2014-10-21 01:32:10 +04:00
|
|
|
|
nsRefPtr<LayerManager> layerManager =
|
|
|
|
|
list.PaintRoot(&builder, aRenderingContext, flags);
|
2014-12-08 23:43:16 +03:00
|
|
|
|
Telemetry::AccumulateTimeDelta(Telemetry::PAINT_RASTERIZE_TIME,
|
|
|
|
|
paintStart);
|
2010-07-16 01:07:51 +04:00
|
|
|
|
|
2014-12-18 21:32:53 +03:00
|
|
|
|
if (consoleNeedsDisplayList || profilerNeedsDisplayList) {
|
2014-12-31 23:17:39 +03:00
|
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
2012-08-07 21:57:26 +04:00
|
|
|
|
if (gfxUtils::sDumpPaintingToFile) {
|
2014-10-21 01:32:10 +04:00
|
|
|
|
*ss << "</script>";
|
2012-08-07 21:57:26 +04:00
|
|
|
|
}
|
2014-12-31 23:17:39 +03:00
|
|
|
|
#endif
|
2014-10-21 01:32:10 +04:00
|
|
|
|
*ss << "Painting --- after optimization:\n";
|
|
|
|
|
nsFrame::PrintDisplayList(&builder, list, *ss, gfxUtils::sDumpPaintingToFile);
|
2011-01-04 06:56:57 +03:00
|
|
|
|
|
2014-10-21 01:32:10 +04:00
|
|
|
|
*ss << "Painting --- layer tree:\n";
|
|
|
|
|
if (layerManager) {
|
|
|
|
|
FrameLayerBuilder::DumpRetainedLayerTree(layerManager, *ss,
|
|
|
|
|
gfxUtils::sDumpPaintingToFile);
|
2012-07-17 21:03:51 +04:00
|
|
|
|
}
|
2014-06-20 02:36:25 +04:00
|
|
|
|
|
2014-12-18 21:32:53 +03:00
|
|
|
|
if (profilerNeedsDisplayList && !consoleNeedsDisplayList) {
|
|
|
|
|
profiler_log(ss->str().c_str());
|
|
|
|
|
} else {
|
|
|
|
|
// Send to the console which will send to the profiler if required.
|
|
|
|
|
fprint_stderr(gfxUtils::sDumpPaintFile, *ss);
|
|
|
|
|
}
|
2014-06-20 02:36:25 +04:00
|
|
|
|
|
2014-12-31 23:17:39 +03:00
|
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
|
|
|
|
if (gfxUtils::sDumpPaintingToFile) {
|
|
|
|
|
*ss << "</body></html>";
|
|
|
|
|
}
|
2014-06-20 02:36:25 +04:00
|
|
|
|
if (gfxUtils::sDumpPaintingToFile) {
|
2012-03-01 12:26:09 +04:00
|
|
|
|
fclose(gfxUtils::sDumpPaintFile);
|
|
|
|
|
}
|
2012-09-25 07:25:47 +04:00
|
|
|
|
gfxUtils::sDumpPaintFile = savedDumpFile;
|
2012-03-01 12:26:09 +04:00
|
|
|
|
gPaintCount++;
|
2010-07-16 01:07:51 +04:00
|
|
|
|
#endif
|
2015-08-03 09:11:00 +03:00
|
|
|
|
|
|
|
|
|
std::stringstream lsStream;
|
|
|
|
|
nsFrame::PrintDisplayList(&builder, list, lsStream);
|
|
|
|
|
layerManager->GetRoot()->SetDisplayListLog(lsStream.str().c_str());
|
2014-12-31 23:17:39 +03:00
|
|
|
|
}
|
2010-07-16 01:07:51 +04:00
|
|
|
|
|
2015-02-04 01:18:44 +03:00
|
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
|
|
|
|
if (gfxPrefs::DumpClientLayers()) {
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
FrameLayerBuilder::DumpRetainedLayerTree(layerManager, ss, false);
|
2015-02-26 23:57:42 +03:00
|
|
|
|
print_stderr(ss);
|
2015-02-04 01:18:44 +03:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-10-06 17:03:23 +04:00
|
|
|
|
// Update the widget's opaque region information. This sets
|
2014-09-18 12:52:27 +04:00
|
|
|
|
// glass boundaries on Windows. Also set up the window dragging region
|
|
|
|
|
// and plugin clip regions and bounds.
|
2012-10-06 17:03:23 +04:00
|
|
|
|
if ((aFlags & PAINT_WIDGET_LAYERS) &&
|
|
|
|
|
!willFlushRetainedLayers &&
|
|
|
|
|
!(aFlags & PAINT_DOCUMENT_RELATIVE)) {
|
|
|
|
|
nsIWidget *widget = aFrame->GetNearestWidget();
|
|
|
|
|
if (widget) {
|
2014-10-29 02:33:52 +03:00
|
|
|
|
nsRegion opaqueRegion;
|
|
|
|
|
opaqueRegion.And(builder.GetWindowExcludeGlassRegion(), builder.GetWindowOpaqueRegion());
|
2014-09-18 12:52:27 +04:00
|
|
|
|
widget->UpdateOpaqueRegion(
|
|
|
|
|
opaqueRegion.ToNearestPixels(presContext->AppUnitsPerDevPixel()));
|
|
|
|
|
|
2015-01-23 21:07:51 +03:00
|
|
|
|
const nsIntRegion& draggingRegion = builder.GetWindowDraggingRegion();
|
|
|
|
|
widget->UpdateWindowDraggingRegion(draggingRegion);
|
2012-10-06 17:03:23 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (builder.WillComputePluginGeometry()) {
|
2015-03-02 14:01:58 +03:00
|
|
|
|
// For single process compute and apply plugin geometry updates to plugin
|
|
|
|
|
// windows, then request composition. For content processes skip eveything
|
|
|
|
|
// except requesting composition. Geometry updates were calculated and
|
|
|
|
|
// shipped to the chrome process in nsDisplayList when the layer
|
|
|
|
|
// transaction completed.
|
2015-07-04 04:29:00 +03:00
|
|
|
|
if (XRE_IsParentProcess()) {
|
2015-03-02 14:01:58 +03:00
|
|
|
|
rootPresContext->ComputePluginGeometryUpdates(aFrame, &builder, &list);
|
|
|
|
|
// We're not going to get a WillPaintWindow event here if we didn't do
|
|
|
|
|
// widget invalidation, so just apply the plugin geometry update here
|
|
|
|
|
// instead. We could instead have the compositor send back an equivalent
|
|
|
|
|
// to WillPaintWindow, but it should be close enough to now not to matter.
|
|
|
|
|
if (layerManager && !layerManager->NeedsWidgetInvalidation()) {
|
2015-01-29 22:41:54 +03:00
|
|
|
|
rootPresContext->ApplyPluginGeometryUpdates();
|
|
|
|
|
}
|
2013-12-16 09:38:42 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-02 14:01:58 +03:00
|
|
|
|
// We told the compositor thread not to composite when it received the
|
|
|
|
|
// transaction because we wanted to update plugins first. Schedule the
|
|
|
|
|
// composite now.
|
2013-12-16 09:38:42 +04:00
|
|
|
|
if (layerManager) {
|
|
|
|
|
layerManager->Composite();
|
|
|
|
|
}
|
2012-10-06 17:03:23 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-16 09:38:42 +04:00
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
|
// Flush the list so we don't trigger the IsEmpty-on-destruction assertion
|
|
|
|
|
list.DeleteAll();
|
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-06 03:32:52 +03:00
|
|
|
|
/**
|
|
|
|
|
* 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 20:15:01 +04:00
|
|
|
|
* @param "aBaseWidth" contains the width in twips of the portion
|
2005-12-06 03:32:52 +03: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-29 10:19:26 +04:00
|
|
|
|
bool
|
2011-04-08 05:04:40 +04:00
|
|
|
|
nsLayoutUtils::BinarySearchForPosition(nsRenderingContext* aRendContext,
|
2014-10-24 19:28:14 +04:00
|
|
|
|
nsFontMetrics& aFontMetrics,
|
2014-01-04 19:02:17 +04:00
|
|
|
|
const char16_t* aText,
|
2012-08-22 19:56:38 +04: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;
|
2006-12-21 10:03:23 +03:00
|
|
|
|
if ((range == 1) || (range == 2 && NS_IS_HIGH_SURROGATE(aText[aStartInx]))) {
|
2005-12-06 03:32:52 +03:00
|
|
|
|
aIndex = aStartInx + aBaseInx;
|
2014-10-24 19:28:13 +04:00
|
|
|
|
aTextWidth = nsLayoutUtils::AppUnitWidthOfString(aText, aIndex,
|
2014-10-24 19:28:14 +04:00
|
|
|
|
aFontMetrics,
|
2014-10-24 19:28:13 +04:00
|
|
|
|
*aRendContext);
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true;
|
2005-12-06 03:32:52 +03:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t inx = aStartInx + (range / 2);
|
2005-12-06 03:32:52 +03:00
|
|
|
|
|
|
|
|
|
// Make sure we don't leave a dangling low surrogate
|
2006-12-21 10:03:23 +03:00
|
|
|
|
if (NS_IS_HIGH_SURROGATE(aText[inx-1]))
|
2005-12-06 03:32:52 +03:00
|
|
|
|
inx++;
|
|
|
|
|
|
2014-10-24 19:28:13 +04:00
|
|
|
|
int32_t textWidth = nsLayoutUtils::AppUnitWidthOfString(aText, inx,
|
2014-10-24 19:28:14 +04:00
|
|
|
|
aFontMetrics,
|
2014-10-24 19:28:13 +04:00
|
|
|
|
*aRendContext);
|
2005-12-06 03:32:52 +03:00
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t fullWidth = aBaseWidth + textWidth;
|
2005-12-06 03:32:52 +03:00
|
|
|
|
if (fullWidth == aCursorPos) {
|
|
|
|
|
aTextWidth = textWidth;
|
|
|
|
|
aIndex = inx;
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true;
|
2005-12-06 03:32:52 +03:00
|
|
|
|
} else if (aCursorPos < fullWidth) {
|
|
|
|
|
aTextWidth = aBaseWidth;
|
2014-10-24 19:28:14 +04:00
|
|
|
|
if (BinarySearchForPosition(aRendContext, aFontMetrics, aText, aBaseWidth,
|
|
|
|
|
aBaseInx, aStartInx, inx, aCursorPos, aIndex,
|
|
|
|
|
aTextWidth)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true;
|
2005-12-06 03:32:52 +03:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
aTextWidth = fullWidth;
|
2014-10-24 19:28:14 +04:00
|
|
|
|
if (BinarySearchForPosition(aRendContext, aFontMetrics, aText, aBaseWidth,
|
|
|
|
|
aBaseInx, inx, aEndInx, aCursorPos, aIndex,
|
|
|
|
|
aTextWidth)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true;
|
2005-12-06 03:32:52 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2005-12-06 03:32:52 +03:00
|
|
|
|
}
|
|
|
|
|
|
2008-02-27 12:26:15 +03:00
|
|
|
|
static void
|
2008-09-11 04:24:16 +04:00
|
|
|
|
AddBoxesForFrame(nsIFrame* aFrame,
|
|
|
|
|
nsLayoutUtils::BoxCallback* aCallback)
|
2006-06-16 06:40:29 +04:00
|
|
|
|
{
|
2013-02-16 09:38:33 +04:00
|
|
|
|
nsIAtom* pseudoType = aFrame->StyleContext()->GetPseudo();
|
2008-02-27 12:26:15 +03:00
|
|
|
|
|
|
|
|
|
if (pseudoType == nsCSSAnonBoxes::tableOuter) {
|
2011-08-25 00:54:30 +04:00
|
|
|
|
AddBoxesForFrame(aFrame->GetFirstPrincipalChild(), aCallback);
|
|
|
|
|
nsIFrame* kid = aFrame->GetFirstChild(nsIFrame::kCaptionList);
|
2008-02-27 12:26:15 +03:00
|
|
|
|
if (kid) {
|
2008-09-11 04:24:16 +04:00
|
|
|
|
AddBoxesForFrame(kid, aCallback);
|
2008-02-27 12:26:15 +03:00
|
|
|
|
}
|
|
|
|
|
} else if (pseudoType == nsCSSAnonBoxes::mozAnonymousBlock ||
|
|
|
|
|
pseudoType == nsCSSAnonBoxes::mozAnonymousPositionedBlock ||
|
|
|
|
|
pseudoType == nsCSSAnonBoxes::mozMathMLAnonymousBlock ||
|
|
|
|
|
pseudoType == nsCSSAnonBoxes::mozXULAnonymousBlock) {
|
2015-06-29 23:02:21 +03:00
|
|
|
|
for (nsIFrame* kid : aFrame->PrincipalChildList()) {
|
2008-09-11 04:24:16 +04:00
|
|
|
|
AddBoxesForFrame(kid, aCallback);
|
2008-02-27 12:26:15 +03:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2008-09-11 04:24:16 +04:00
|
|
|
|
aCallback->AddBox(aFrame);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nsLayoutUtils::GetAllInFlowBoxes(nsIFrame* aFrame, BoxCallback* aCallback)
|
|
|
|
|
{
|
|
|
|
|
while (aFrame) {
|
|
|
|
|
AddBoxesForFrame(aFrame, aCallback);
|
2014-02-07 05:45:31 +04:00
|
|
|
|
aFrame = nsLayoutUtils::GetNextContinuationOrIBSplitSibling(aFrame);
|
2008-09-11 04:24:16 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-20 14:21:03 +04:00
|
|
|
|
nsIFrame*
|
|
|
|
|
nsLayoutUtils::GetFirstNonAnonymousFrame(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
while (aFrame) {
|
|
|
|
|
nsIAtom* pseudoType = aFrame->StyleContext()->GetPseudo();
|
|
|
|
|
|
|
|
|
|
if (pseudoType == nsCSSAnonBoxes::tableOuter) {
|
|
|
|
|
nsIFrame* f = GetFirstNonAnonymousFrame(aFrame->GetFirstPrincipalChild());
|
|
|
|
|
if (f) {
|
|
|
|
|
return f;
|
|
|
|
|
}
|
|
|
|
|
nsIFrame* kid = aFrame->GetFirstChild(nsIFrame::kCaptionList);
|
|
|
|
|
if (kid) {
|
|
|
|
|
f = GetFirstNonAnonymousFrame(kid);
|
|
|
|
|
if (f) {
|
|
|
|
|
return f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (pseudoType == nsCSSAnonBoxes::mozAnonymousBlock ||
|
|
|
|
|
pseudoType == nsCSSAnonBoxes::mozAnonymousPositionedBlock ||
|
|
|
|
|
pseudoType == nsCSSAnonBoxes::mozMathMLAnonymousBlock ||
|
|
|
|
|
pseudoType == nsCSSAnonBoxes::mozXULAnonymousBlock) {
|
2015-06-29 23:02:21 +03:00
|
|
|
|
for (nsIFrame* kid : aFrame->PrincipalChildList()) {
|
2013-09-20 14:21:03 +04:00
|
|
|
|
nsIFrame* f = GetFirstNonAnonymousFrame(kid);
|
|
|
|
|
if (f) {
|
|
|
|
|
return f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return aFrame;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
aFrame = nsLayoutUtils::GetNextContinuationOrIBSplitSibling(aFrame);
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-21 17:35:17 +04:00
|
|
|
|
struct BoxToRect : public nsLayoutUtils::BoxCallback {
|
2011-12-28 07:24:29 +04:00
|
|
|
|
nsIFrame* mRelativeTo;
|
2008-09-11 04:24:16 +04:00
|
|
|
|
nsLayoutUtils::RectCallback* mCallback;
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t mFlags;
|
2008-09-11 04:24:16 +04:00
|
|
|
|
|
2012-06-21 17:35:17 +04:00
|
|
|
|
BoxToRect(nsIFrame* aRelativeTo, nsLayoutUtils::RectCallback* aCallback,
|
2013-12-03 23:13:16 +04:00
|
|
|
|
uint32_t aFlags)
|
|
|
|
|
: mRelativeTo(aRelativeTo), mCallback(aCallback), mFlags(aFlags) {}
|
2008-09-11 04:24:16 +04:00
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
|
virtual void AddBox(nsIFrame* aFrame) override {
|
2008-02-27 12:26:15 +03:00
|
|
|
|
nsRect r;
|
|
|
|
|
nsIFrame* outer = nsSVGUtils::GetOuterSVGFrameAndCoveredRegion(aFrame, &r);
|
2011-12-28 07:24:29 +04:00
|
|
|
|
if (!outer) {
|
|
|
|
|
outer = aFrame;
|
2013-12-03 23:13:16 +04:00
|
|
|
|
switch (mFlags & nsLayoutUtils::RECTS_WHICH_BOX_MASK) {
|
|
|
|
|
case nsLayoutUtils::RECTS_USE_CONTENT_BOX:
|
|
|
|
|
r = aFrame->GetContentRectRelativeToSelf();
|
|
|
|
|
break;
|
|
|
|
|
case nsLayoutUtils::RECTS_USE_PADDING_BOX:
|
|
|
|
|
r = aFrame->GetPaddingRectRelativeToSelf();
|
|
|
|
|
break;
|
|
|
|
|
case nsLayoutUtils::RECTS_USE_MARGIN_BOX:
|
|
|
|
|
r = aFrame->GetMarginRectRelativeToSelf();
|
|
|
|
|
break;
|
|
|
|
|
default: // Use the border box
|
|
|
|
|
r = aFrame->GetRectRelativeToSelf();
|
|
|
|
|
}
|
2011-12-28 07:24:29 +04:00
|
|
|
|
}
|
|
|
|
|
if (mFlags & nsLayoutUtils::RECTS_ACCOUNT_FOR_TRANSFORMS) {
|
|
|
|
|
r = nsLayoutUtils::TransformFrameRectToAncestor(outer, r, mRelativeTo);
|
|
|
|
|
} else {
|
|
|
|
|
r += outer->GetOffsetTo(mRelativeTo);
|
|
|
|
|
}
|
|
|
|
|
mCallback->AddRect(r);
|
2006-06-16 06:40:29 +04:00
|
|
|
|
}
|
2008-09-11 04:24:16 +04:00
|
|
|
|
};
|
2006-06-16 06:40:29 +04:00
|
|
|
|
|
2008-02-27 12:26:15 +03:00
|
|
|
|
void
|
|
|
|
|
nsLayoutUtils::GetAllInFlowRects(nsIFrame* aFrame, nsIFrame* aRelativeTo,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
RectCallback* aCallback, uint32_t aFlags)
|
2008-02-27 12:26:15 +03:00
|
|
|
|
{
|
2013-12-03 23:13:16 +04:00
|
|
|
|
BoxToRect converter(aRelativeTo, aCallback, aFlags);
|
2012-06-21 17:35:17 +04:00
|
|
|
|
GetAllInFlowBoxes(aFrame, &converter);
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
|
nsLayoutUtils::RectAccumulator::RectAccumulator() : mSeenFirstRect(false) {}
|
2006-06-16 06:40:29 +04:00
|
|
|
|
|
2009-09-25 01:01:48 +04:00
|
|
|
|
void nsLayoutUtils::RectAccumulator::AddRect(const nsRect& aRect) {
|
|
|
|
|
mResultRect.UnionRect(mResultRect, aRect);
|
|
|
|
|
if (!mSeenFirstRect) {
|
2011-10-17 18:59:28 +04:00
|
|
|
|
mSeenFirstRect = true;
|
2009-09-25 01:01:48 +04:00
|
|
|
|
mFirstRect = aRect;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-27 12:26:15 +03:00
|
|
|
|
|
2013-09-20 14:21:03 +04:00
|
|
|
|
nsLayoutUtils::RectListBuilder::RectListBuilder(DOMRectList* aList)
|
2013-03-17 11:55:16 +04:00
|
|
|
|
: mRectList(aList)
|
|
|
|
|
{
|
|
|
|
|
}
|
2009-09-25 01:01:48 +04:00
|
|
|
|
|
|
|
|
|
void nsLayoutUtils::RectListBuilder::AddRect(const nsRect& aRect) {
|
2013-09-20 14:21:03 +04:00
|
|
|
|
nsRefPtr<DOMRect> rect = new DOMRect(mRectList);
|
2009-09-25 01:01:48 +04:00
|
|
|
|
|
|
|
|
|
rect->SetLayoutRect(aRect);
|
|
|
|
|
mRectList->Append(rect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIFrame* nsLayoutUtils::GetContainingBlockForClientRect(nsIFrame* aFrame)
|
|
|
|
|
{
|
2011-12-28 07:24:29 +04:00
|
|
|
|
return aFrame->PresContext()->PresShell()->GetRootFrame();
|
2009-09-25 01:01:48 +04:00
|
|
|
|
}
|
2008-02-27 12:26:15 +03:00
|
|
|
|
|
|
|
|
|
nsRect
|
2011-12-28 07:24:29 +04:00
|
|
|
|
nsLayoutUtils::GetAllInFlowRectsUnion(nsIFrame* aFrame, nsIFrame* aRelativeTo,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t aFlags) {
|
2008-02-27 12:26:15 +03:00
|
|
|
|
RectAccumulator accumulator;
|
2011-12-28 07:24:29 +04:00
|
|
|
|
GetAllInFlowRects(aFrame, aRelativeTo, &accumulator, aFlags);
|
2008-02-27 12:26:15 +03:00
|
|
|
|
return accumulator.mResultRect.IsEmpty() ? accumulator.mFirstRect
|
|
|
|
|
: accumulator.mResultRect;
|
2006-06-16 06:40:29 +04:00
|
|
|
|
}
|
2006-07-06 14:43:51 +04:00
|
|
|
|
|
2008-06-13 02:02:32 +04:00
|
|
|
|
nsRect
|
|
|
|
|
nsLayoutUtils::GetTextShadowRectsUnion(const nsRect& aTextAndDecorationsRect,
|
2011-01-03 04:48:09 +03:00
|
|
|
|
nsIFrame* aFrame,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t aFlags)
|
2008-06-13 02:02:32 +04:00
|
|
|
|
{
|
2013-02-17 01:51:02 +04:00
|
|
|
|
const nsStyleText* textStyle = aFrame->StyleText();
|
2014-01-13 16:21:42 +04:00
|
|
|
|
if (!textStyle->HasTextShadow())
|
2008-06-13 02:02:32 +04:00
|
|
|
|
return aTextAndDecorationsRect;
|
|
|
|
|
|
|
|
|
|
nsRect resultRect = aTextAndDecorationsRect;
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t A2D = aFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
|
for (uint32_t i = 0; i < textStyle->mTextShadow->Length(); ++i) {
|
2008-07-08 04:56:52 +04:00
|
|
|
|
nsCSSShadowItem* shadow = textStyle->mTextShadow->ShadowAt(i);
|
2011-01-03 04:48:09 +03: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-13 02:02:32 +04:00
|
|
|
|
|
2008-09-13 07:45:37 +04:00
|
|
|
|
tmpRect.MoveBy(nsPoint(shadow->mXOffset, shadow->mYOffset));
|
2011-01-03 04:48:09 +03:00
|
|
|
|
tmpRect.Inflate(blur);
|
2008-06-13 02:02:32 +04:00
|
|
|
|
|
|
|
|
|
resultRect.UnionRect(resultRect, tmpRect);
|
|
|
|
|
}
|
|
|
|
|
return resultRect;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-15 03:45:23 +03:00
|
|
|
|
enum ObjectDimensionType { eWidth, eHeight };
|
|
|
|
|
static nscoord
|
|
|
|
|
ComputeMissingDimension(const nsSize& aDefaultObjectSize,
|
|
|
|
|
const nsSize& aIntrinsicRatio,
|
|
|
|
|
const Maybe<nscoord>& aSpecifiedWidth,
|
|
|
|
|
const Maybe<nscoord>& aSpecifiedHeight,
|
|
|
|
|
ObjectDimensionType aDimensionToCompute)
|
|
|
|
|
{
|
|
|
|
|
// The "default sizing algorithm" computes the missing dimension as follows:
|
|
|
|
|
// (source: http://dev.w3.org/csswg/css-images-3/#default-sizing )
|
|
|
|
|
|
|
|
|
|
// 1. "If the object has an intrinsic aspect ratio, the missing dimension of
|
|
|
|
|
// the concrete object size is calculated using the intrinsic aspect
|
|
|
|
|
// ratio and the present dimension."
|
|
|
|
|
if (aIntrinsicRatio.width > 0 && aIntrinsicRatio.height > 0) {
|
|
|
|
|
// Fill in the missing dimension using the intrinsic aspect ratio.
|
|
|
|
|
nscoord knownDimensionSize;
|
|
|
|
|
float ratio;
|
|
|
|
|
if (aDimensionToCompute == eWidth) {
|
|
|
|
|
knownDimensionSize = *aSpecifiedHeight;
|
|
|
|
|
ratio = aIntrinsicRatio.width / aIntrinsicRatio.height;
|
|
|
|
|
} else {
|
|
|
|
|
knownDimensionSize = *aSpecifiedWidth;
|
|
|
|
|
ratio = aIntrinsicRatio.height / aIntrinsicRatio.width;
|
|
|
|
|
}
|
|
|
|
|
return NSCoordSaturatingNonnegativeMultiply(knownDimensionSize, ratio);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2. "Otherwise, if the missing dimension is present in the object’s
|
|
|
|
|
// intrinsic dimensions, [...]"
|
|
|
|
|
// NOTE: *Skipping* this case, because we already know it's not true -- we're
|
|
|
|
|
// in this function because the missing dimension is *not* present in
|
|
|
|
|
// the object's intrinsic dimensions.
|
|
|
|
|
|
|
|
|
|
// 3. "Otherwise, the missing dimension of the concrete object size is taken
|
|
|
|
|
// from the default object size. "
|
|
|
|
|
return (aDimensionToCompute == eWidth) ?
|
|
|
|
|
aDefaultObjectSize.width : aDefaultObjectSize.height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This computes & returns the concrete object size of replaced content, if
|
|
|
|
|
* that content were to be rendered with "object-fit: none". (Or, if the
|
|
|
|
|
* element has neither an intrinsic height nor width, this method returns an
|
|
|
|
|
* empty Maybe<> object.)
|
|
|
|
|
*
|
|
|
|
|
* As specced...
|
|
|
|
|
* http://dev.w3.org/csswg/css-images-3/#valdef-object-fit-none
|
|
|
|
|
* ..we use "the default sizing algorithm with no specified size,
|
|
|
|
|
* and a default object size equal to the replaced element's used width and
|
|
|
|
|
* height."
|
|
|
|
|
*
|
|
|
|
|
* The default sizing algorithm is described here:
|
|
|
|
|
* http://dev.w3.org/csswg/css-images-3/#default-sizing
|
|
|
|
|
* Quotes in the function-impl are taken from that ^ spec-text.
|
|
|
|
|
*
|
|
|
|
|
* Per its final bulleted section: since there's no specified size,
|
|
|
|
|
* we run the default sizing algorithm using the object's intrinsic size in
|
|
|
|
|
* place of the specified size. But if the object has neither an intrinsic
|
|
|
|
|
* height nor an intrinsic width, then we instead return without populating our
|
|
|
|
|
* outparam, and we let the caller figure out the size (using a contain
|
|
|
|
|
* constraint).
|
|
|
|
|
*/
|
|
|
|
|
static Maybe<nsSize>
|
|
|
|
|
MaybeComputeObjectFitNoneSize(const nsSize& aDefaultObjectSize,
|
|
|
|
|
const IntrinsicSize& aIntrinsicSize,
|
|
|
|
|
const nsSize& aIntrinsicRatio)
|
|
|
|
|
{
|
|
|
|
|
// "If the object has an intrinsic height or width, its size is resolved as
|
|
|
|
|
// if its intrinsic dimensions were given as the specified size."
|
|
|
|
|
//
|
|
|
|
|
// So, first we check if we have an intrinsic height and/or width:
|
|
|
|
|
Maybe<nscoord> specifiedWidth;
|
|
|
|
|
if (aIntrinsicSize.width.GetUnit() == eStyleUnit_Coord) {
|
|
|
|
|
specifiedWidth.emplace(aIntrinsicSize.width.GetCoordValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Maybe<nscoord> specifiedHeight;
|
|
|
|
|
if (aIntrinsicSize.height.GetUnit() == eStyleUnit_Coord) {
|
|
|
|
|
specifiedHeight.emplace(aIntrinsicSize.height.GetCoordValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Maybe<nsSize> noneSize; // (the value we'll return)
|
|
|
|
|
if (specifiedWidth || specifiedHeight) {
|
|
|
|
|
// We have at least one specified dimension; use whichever dimension is
|
|
|
|
|
// specified, and compute the other one using our intrinsic ratio, or (if
|
|
|
|
|
// no valid ratio) using the default object size.
|
|
|
|
|
noneSize.emplace();
|
|
|
|
|
|
|
|
|
|
noneSize->width = specifiedWidth ?
|
|
|
|
|
*specifiedWidth :
|
|
|
|
|
ComputeMissingDimension(aDefaultObjectSize, aIntrinsicRatio,
|
|
|
|
|
specifiedWidth, specifiedHeight,
|
|
|
|
|
eWidth);
|
|
|
|
|
|
|
|
|
|
noneSize->height = specifiedHeight ?
|
|
|
|
|
*specifiedHeight :
|
|
|
|
|
ComputeMissingDimension(aDefaultObjectSize, aIntrinsicRatio,
|
|
|
|
|
specifiedWidth, specifiedHeight,
|
|
|
|
|
eHeight);
|
|
|
|
|
}
|
|
|
|
|
// [else:] "Otherwise [if there's neither an intrinsic height nor width], its
|
|
|
|
|
// size is resolved as a contain constraint against the default object size."
|
|
|
|
|
// We'll let our caller do that, to share code & avoid redundant
|
|
|
|
|
// computations; so, we return w/out populating noneSize.
|
|
|
|
|
return noneSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Computes the concrete object size to render into, as described at
|
|
|
|
|
// http://dev.w3.org/csswg/css-images-3/#concrete-size-resolution
|
|
|
|
|
static nsSize
|
|
|
|
|
ComputeConcreteObjectSize(const nsSize& aConstraintSize,
|
|
|
|
|
const IntrinsicSize& aIntrinsicSize,
|
|
|
|
|
const nsSize& aIntrinsicRatio,
|
|
|
|
|
uint8_t aObjectFit)
|
|
|
|
|
{
|
|
|
|
|
// Handle default behavior (filling the container) w/ fast early return.
|
|
|
|
|
// (Also: if there's no valid intrinsic ratio, then we have the "fill"
|
|
|
|
|
// behavior & just use the constraint size.)
|
|
|
|
|
if (MOZ_LIKELY(aObjectFit == NS_STYLE_OBJECT_FIT_FILL) ||
|
|
|
|
|
aIntrinsicRatio.width == 0 ||
|
|
|
|
|
aIntrinsicRatio.height == 0) {
|
|
|
|
|
return aConstraintSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The type of constraint to compute (cover/contain), if needed:
|
|
|
|
|
Maybe<nsImageRenderer::FitType> fitType;
|
|
|
|
|
|
|
|
|
|
Maybe<nsSize> noneSize;
|
|
|
|
|
if (aObjectFit == NS_STYLE_OBJECT_FIT_NONE ||
|
|
|
|
|
aObjectFit == NS_STYLE_OBJECT_FIT_SCALE_DOWN) {
|
|
|
|
|
noneSize = MaybeComputeObjectFitNoneSize(aConstraintSize, aIntrinsicSize,
|
|
|
|
|
aIntrinsicRatio);
|
|
|
|
|
if (!noneSize || aObjectFit == NS_STYLE_OBJECT_FIT_SCALE_DOWN) {
|
|
|
|
|
// Need to compute a 'CONTAIN' constraint (either for the 'none' size
|
|
|
|
|
// itself, or for comparison w/ the 'none' size to resolve 'scale-down'.)
|
|
|
|
|
fitType.emplace(nsImageRenderer::CONTAIN);
|
|
|
|
|
}
|
|
|
|
|
} else if (aObjectFit == NS_STYLE_OBJECT_FIT_COVER) {
|
|
|
|
|
fitType.emplace(nsImageRenderer::COVER);
|
|
|
|
|
} else if (aObjectFit == NS_STYLE_OBJECT_FIT_CONTAIN) {
|
|
|
|
|
fitType.emplace(nsImageRenderer::CONTAIN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Maybe<nsSize> constrainedSize;
|
|
|
|
|
if (fitType) {
|
|
|
|
|
constrainedSize.emplace(
|
|
|
|
|
nsImageRenderer::ComputeConstrainedSize(aConstraintSize,
|
|
|
|
|
aIntrinsicRatio,
|
|
|
|
|
*fitType));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now, we should have all the sizing information that we need.
|
|
|
|
|
switch (aObjectFit) {
|
|
|
|
|
// skipping NS_STYLE_OBJECT_FIT_FILL; we handled it w/ early-return.
|
|
|
|
|
case NS_STYLE_OBJECT_FIT_CONTAIN:
|
|
|
|
|
case NS_STYLE_OBJECT_FIT_COVER:
|
|
|
|
|
MOZ_ASSERT(constrainedSize);
|
|
|
|
|
return *constrainedSize;
|
|
|
|
|
|
|
|
|
|
case NS_STYLE_OBJECT_FIT_NONE:
|
|
|
|
|
if (noneSize) {
|
|
|
|
|
return *noneSize;
|
|
|
|
|
}
|
|
|
|
|
MOZ_ASSERT(constrainedSize);
|
|
|
|
|
return *constrainedSize;
|
|
|
|
|
|
|
|
|
|
case NS_STYLE_OBJECT_FIT_SCALE_DOWN:
|
|
|
|
|
MOZ_ASSERT(constrainedSize);
|
|
|
|
|
if (noneSize) {
|
|
|
|
|
constrainedSize->width =
|
|
|
|
|
std::min(constrainedSize->width, noneSize->width);
|
|
|
|
|
constrainedSize->height =
|
|
|
|
|
std::min(constrainedSize->height, noneSize->height);
|
|
|
|
|
}
|
|
|
|
|
return *constrainedSize;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Unexpected enum value for 'object-fit'");
|
|
|
|
|
return aConstraintSize; // fall back to (default) 'fill' behavior
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-26 03:46:14 +03:00
|
|
|
|
// (Helper for HasInitialObjectFitAndPosition, to check
|
|
|
|
|
// each "object-position" coord.)
|
|
|
|
|
typedef nsStyleBackground::Position::PositionCoord PositionCoord;
|
|
|
|
|
static bool
|
|
|
|
|
IsCoord50Pct(const PositionCoord& aCoord)
|
|
|
|
|
{
|
|
|
|
|
return (aCoord.mLength == 0 &&
|
|
|
|
|
aCoord.mHasPercent &&
|
|
|
|
|
aCoord.mPercent == 0.5f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Indicates whether the given nsStylePosition has the initial values
|
|
|
|
|
// for the "object-fit" and "object-position" properties.
|
|
|
|
|
static bool
|
|
|
|
|
HasInitialObjectFitAndPosition(const nsStylePosition* aStylePos)
|
|
|
|
|
{
|
|
|
|
|
const nsStyleBackground::Position& objectPos = aStylePos->mObjectPosition;
|
|
|
|
|
|
|
|
|
|
return aStylePos->mObjectFit == NS_STYLE_OBJECT_FIT_FILL &&
|
|
|
|
|
IsCoord50Pct(objectPos.mXPosition) &&
|
|
|
|
|
IsCoord50Pct(objectPos.mYPosition);
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-15 03:45:23 +03:00
|
|
|
|
/* static */ nsRect
|
|
|
|
|
nsLayoutUtils::ComputeObjectDestRect(const nsRect& aConstraintRect,
|
|
|
|
|
const IntrinsicSize& aIntrinsicSize,
|
|
|
|
|
const nsSize& aIntrinsicRatio,
|
2014-11-22 05:25:46 +03:00
|
|
|
|
const nsStylePosition* aStylePos,
|
|
|
|
|
nsPoint* aAnchorPoint)
|
2014-11-15 03:45:23 +03:00
|
|
|
|
{
|
|
|
|
|
// Step 1: Figure out our "concrete object size"
|
|
|
|
|
// (the size of the region we'll actually draw our image's pixels into).
|
|
|
|
|
nsSize concreteObjectSize =
|
|
|
|
|
ComputeConcreteObjectSize(aConstraintRect.Size(), aIntrinsicSize,
|
|
|
|
|
aIntrinsicRatio, aStylePos->mObjectFit);
|
|
|
|
|
|
|
|
|
|
// Step 2: Figure out how to align that region in the element's content-box.
|
|
|
|
|
nsPoint imageTopLeftPt, imageAnchorPt;
|
|
|
|
|
nsImageRenderer::ComputeObjectAnchorPoint(aStylePos->mObjectPosition,
|
|
|
|
|
aConstraintRect.Size(),
|
|
|
|
|
concreteObjectSize,
|
|
|
|
|
&imageTopLeftPt, &imageAnchorPt);
|
|
|
|
|
// Right now, we're with respect to aConstraintRect's top-left point. We add
|
|
|
|
|
// that point here, to convert to the same broader coordinate space that
|
|
|
|
|
// aConstraintRect is in.
|
|
|
|
|
imageTopLeftPt += aConstraintRect.TopLeft();
|
|
|
|
|
imageAnchorPt += aConstraintRect.TopLeft();
|
|
|
|
|
|
2014-11-22 05:25:46 +03:00
|
|
|
|
if (aAnchorPoint) {
|
2014-11-26 03:46:14 +03:00
|
|
|
|
// Special-case: if our "object-fit" and "object-position" properties have
|
|
|
|
|
// their default values ("object-fit: fill; object-position:50% 50%"), then
|
|
|
|
|
// we'll override the calculated imageAnchorPt, and instead use the
|
|
|
|
|
// object's top-left corner.
|
|
|
|
|
//
|
|
|
|
|
// This special case is partly for backwards compatibility (since
|
|
|
|
|
// traditionally we've pixel-aligned the top-left corner of e.g. <img>
|
|
|
|
|
// elements), and partly because ComputeSnappedDrawingParameters produces
|
|
|
|
|
// less error if the anchor point is at the top-left corner. So, all other
|
|
|
|
|
// things being equal, we prefer that code path with less error.
|
|
|
|
|
if (HasInitialObjectFitAndPosition(aStylePos)) {
|
|
|
|
|
*aAnchorPoint = imageTopLeftPt;
|
|
|
|
|
} else {
|
|
|
|
|
*aAnchorPoint = imageAnchorPt;
|
|
|
|
|
}
|
2014-11-22 05:25:46 +03:00
|
|
|
|
}
|
2014-11-15 03:45:23 +03:00
|
|
|
|
return nsRect(imageTopLeftPt, concreteObjectSize);
|
|
|
|
|
}
|
|
|
|
|
|
2006-07-06 14:43:51 +04:00
|
|
|
|
nsresult
|
2010-08-31 22:54:44 +04:00
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(const nsIFrame* aFrame,
|
2011-11-24 06:48:23 +04:00
|
|
|
|
nsFontMetrics** aFontMetrics,
|
|
|
|
|
float aInflation)
|
2006-07-06 14:43:51 +04:00
|
|
|
|
{
|
2013-02-16 09:38:33 +04:00
|
|
|
|
return nsLayoutUtils::GetFontMetricsForStyleContext(aFrame->StyleContext(),
|
2011-11-24 06:48:23 +04:00
|
|
|
|
aFontMetrics,
|
|
|
|
|
aInflation);
|
2007-08-07 23:22:26 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
|
nsLayoutUtils::GetFontMetricsForStyleContext(nsStyleContext* aStyleContext,
|
2011-11-24 06:48:23 +04:00
|
|
|
|
nsFontMetrics** aFontMetrics,
|
|
|
|
|
float aInflation)
|
2007-08-07 23:22:26 +04:00
|
|
|
|
{
|
2008-10-01 07:01:53 +04:00
|
|
|
|
// pass the user font set object into the device context to pass along to CreateFontGroup
|
2013-11-25 08:59:56 +04:00
|
|
|
|
nsPresContext* pc = aStyleContext->PresContext();
|
|
|
|
|
gfxUserFontSet* fs = pc->GetUserFontSet();
|
|
|
|
|
gfxTextPerfMetrics* tp = pc->GetTextPerfMetrics();
|
2010-04-27 20:15:01 +04:00
|
|
|
|
|
2014-11-13 11:58:04 +03:00
|
|
|
|
WritingMode wm(aStyleContext);
|
2014-12-17 02:02:37 +03:00
|
|
|
|
gfxFont::Orientation orientation =
|
|
|
|
|
wm.IsVertical() && !wm.IsSideways() ? gfxFont::eVertical
|
|
|
|
|
: gfxFont::eHorizontal;
|
|
|
|
|
|
|
|
|
|
const nsStyleFont* styleFont = aStyleContext->StyleFont();
|
|
|
|
|
|
|
|
|
|
// When aInflation is 1.0, avoid making a local copy of the nsFont.
|
|
|
|
|
// This also avoids running font.size through floats when it is large,
|
|
|
|
|
// which would be lossy. Fortunately, in such cases, aInflation is
|
|
|
|
|
// guaranteed to be 1.0f.
|
|
|
|
|
if (aInflation == 1.0f) {
|
|
|
|
|
return pc->DeviceContext()->GetMetricsFor(styleFont->mFont,
|
|
|
|
|
styleFont->mLanguage,
|
2014-12-23 15:50:10 +03:00
|
|
|
|
styleFont->mExplicitLanguage,
|
2014-12-17 02:02:37 +03:00
|
|
|
|
orientation, fs, tp,
|
|
|
|
|
*aFontMetrics);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsFont font = styleFont->mFont;
|
|
|
|
|
font.size = NSToCoordRound(font.size * aInflation);
|
|
|
|
|
return pc->DeviceContext()->GetMetricsFor(font, styleFont->mLanguage,
|
2014-12-23 15:50:10 +03:00
|
|
|
|
styleFont->mExplicitLanguage,
|
2014-12-17 02:02:37 +03:00
|
|
|
|
orientation, fs, tp,
|
|
|
|
|
*aFontMetrics);
|
2006-07-06 14:43:51 +04:00
|
|
|
|
}
|
2006-10-19 05:47:47 +04:00
|
|
|
|
|
2007-01-17 05:37:19 +03: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-21 06:28:18 +03:00
|
|
|
|
nsBlockFrame*
|
|
|
|
|
nsLayoutUtils::GetAsBlock(nsIFrame* aFrame)
|
|
|
|
|
{
|
2009-01-12 22:20:59 +03:00
|
|
|
|
nsBlockFrame* block = do_QueryFrame(aFrame);
|
|
|
|
|
return block;
|
2007-12-21 06:28:18 +03:00
|
|
|
|
}
|
|
|
|
|
|
2007-01-17 05:37:19 +03:00
|
|
|
|
nsBlockFrame*
|
|
|
|
|
nsLayoutUtils::FindNearestBlockAncestor(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
nsIFrame* nextAncestor;
|
|
|
|
|
for (nextAncestor = aFrame->GetParent(); nextAncestor;
|
|
|
|
|
nextAncestor = nextAncestor->GetParent()) {
|
2007-12-21 06:28:18 +03:00
|
|
|
|
nsBlockFrame* block = GetAsBlock(nextAncestor);
|
|
|
|
|
if (block)
|
2007-01-17 05:37:19 +03:00
|
|
|
|
return block;
|
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
|
return nullptr;
|
2007-01-17 05:37:19 +03:00
|
|
|
|
}
|
|
|
|
|
|
2008-11-26 01:15:41 +03:00
|
|
|
|
nsIFrame*
|
|
|
|
|
nsLayoutUtils::GetNonGeneratedAncestor(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
if (!(aFrame->GetStateBits() & NS_FRAME_GENERATED_CONTENT))
|
|
|
|
|
return aFrame;
|
|
|
|
|
|
|
|
|
|
nsIFrame* f = aFrame;
|
|
|
|
|
do {
|
2012-06-11 03:44:50 +04:00
|
|
|
|
f = GetParentOrPlaceholderFor(f);
|
2008-11-26 01:15:41 +03:00
|
|
|
|
} while (f->GetStateBits() & NS_FRAME_GENERATED_CONTENT);
|
|
|
|
|
return f;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-19 05:47:47 +04:00
|
|
|
|
nsIFrame*
|
2012-06-11 03:44:50 +04:00
|
|
|
|
nsLayoutUtils::GetParentOrPlaceholderFor(nsIFrame* aFrame)
|
2006-10-19 05:47:47 +04:00
|
|
|
|
{
|
2007-10-02 09:57:45 +04:00
|
|
|
|
if ((aFrame->GetStateBits() & NS_FRAME_OUT_OF_FLOW)
|
2009-08-31 22:25:36 +04:00
|
|
|
|
&& !aFrame->GetPrevInFlow()) {
|
2012-06-11 03:44:50 +04:00
|
|
|
|
return aFrame->PresContext()->PresShell()->FrameManager()->
|
|
|
|
|
GetPlaceholderFrameFor(aFrame);
|
2007-10-02 09:57:45 +04:00
|
|
|
|
}
|
2006-10-19 05:47:47 +04:00
|
|
|
|
return aFrame->GetParent();
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-11 03:44:50 +04:00
|
|
|
|
nsIFrame*
|
|
|
|
|
nsLayoutUtils::GetParentOrPlaceholderForCrossDoc(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
nsIFrame* f = GetParentOrPlaceholderFor(aFrame);
|
|
|
|
|
if (f)
|
|
|
|
|
return f;
|
|
|
|
|
return GetCrossDocParentFrame(aFrame);
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-26 07:27:53 +04:00
|
|
|
|
nsIFrame*
|
2014-02-07 05:45:31 +04:00
|
|
|
|
nsLayoutUtils::GetNextContinuationOrIBSplitSibling(nsIFrame *aFrame)
|
2007-03-26 07:27:53 +04:00
|
|
|
|
{
|
|
|
|
|
nsIFrame *result = aFrame->GetNextContinuation();
|
|
|
|
|
if (result)
|
|
|
|
|
return result;
|
|
|
|
|
|
2014-02-07 05:45:28 +04:00
|
|
|
|
if ((aFrame->GetStateBits() & NS_FRAME_PART_OF_IBSPLIT) != 0) {
|
2014-02-07 05:45:33 +04:00
|
|
|
|
// We only store the ib-split sibling annotation with the first
|
2009-04-15 06:28:27 +04:00
|
|
|
|
// frame in the continuation chain. Walk back to find that frame now.
|
2013-09-25 15:42:34 +04:00
|
|
|
|
aFrame = aFrame->FirstContinuation();
|
2007-03-26 07:27:53 +04:00
|
|
|
|
|
2014-02-07 05:45:30 +04:00
|
|
|
|
void* value = aFrame->Properties().Get(nsIFrame::IBSplitSibling());
|
2007-07-08 11:08:04 +04:00
|
|
|
|
return static_cast<nsIFrame*>(value);
|
2007-03-26 07:27:53 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
|
return nullptr;
|
2007-03-26 07:27:53 +04:00
|
|
|
|
}
|
|
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
|
nsIFrame*
|
2014-02-07 05:45:31 +04:00
|
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(nsIFrame *aFrame)
|
2008-09-11 04:24:16 +04:00
|
|
|
|
{
|
2013-09-25 15:42:34 +04:00
|
|
|
|
nsIFrame *result = aFrame->FirstContinuation();
|
2014-02-07 05:45:28 +04:00
|
|
|
|
if (result->GetStateBits() & NS_FRAME_PART_OF_IBSPLIT) {
|
2011-10-17 18:59:28 +04:00
|
|
|
|
while (true) {
|
2008-09-11 04:24:16 +04:00
|
|
|
|
nsIFrame *f = static_cast<nsIFrame*>
|
2014-02-07 05:45:31 +04:00
|
|
|
|
(result->Properties().Get(nsIFrame::IBSplitPrevSibling()));
|
2008-09-11 04:24:16 +04:00
|
|
|
|
if (!f)
|
|
|
|
|
break;
|
|
|
|
|
result = f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-12 02:43:10 +03:00
|
|
|
|
nsIFrame*
|
|
|
|
|
nsLayoutUtils::LastContinuationOrIBSplitSibling(nsIFrame *aFrame)
|
|
|
|
|
{
|
|
|
|
|
nsIFrame *result = aFrame->FirstContinuation();
|
|
|
|
|
if (result->GetStateBits() & NS_FRAME_PART_OF_IBSPLIT) {
|
|
|
|
|
while (true) {
|
|
|
|
|
nsIFrame *f = static_cast<nsIFrame*>
|
|
|
|
|
(result->Properties().Get(nsIFrame::IBSplitSibling()));
|
|
|
|
|
if (!f)
|
|
|
|
|
break;
|
|
|
|
|
result = f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = result->LastContinuation();
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-25 23:28:08 +04:00
|
|
|
|
bool
|
2014-02-07 05:45:31 +04:00
|
|
|
|
nsLayoutUtils::IsFirstContinuationOrIBSplitSibling(nsIFrame *aFrame)
|
2013-09-25 23:28:08 +04:00
|
|
|
|
{
|
|
|
|
|
if (aFrame->GetPrevContinuation()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-02-07 05:45:28 +04:00
|
|
|
|
if ((aFrame->GetStateBits() & NS_FRAME_PART_OF_IBSPLIT) &&
|
2014-02-07 05:45:31 +04:00
|
|
|
|
aFrame->Properties().Get(nsIFrame::IBSplitPrevSibling())) {
|
2013-09-25 23:28:08 +04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool
|
2006-11-01 16:56:48 +03:00
|
|
|
|
nsLayoutUtils::IsViewportScrollbarFrame(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
if (!aFrame)
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2006-11-01 16:56:48 +03:00
|
|
|
|
|
|
|
|
|
nsIFrame* rootScrollFrame =
|
2007-03-31 01:11:41 +04:00
|
|
|
|
aFrame->PresContext()->PresShell()->GetRootScrollFrame();
|
2006-11-01 16:56:48 +03:00
|
|
|
|
if (!rootScrollFrame)
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2006-11-01 16:56:48 +03:00
|
|
|
|
|
2009-01-12 22:20:59 +03:00
|
|
|
|
nsIScrollableFrame* rootScrollableFrame = do_QueryFrame(rootScrollFrame);
|
2006-11-01 16:56:48 +03:00
|
|
|
|
NS_ASSERTION(rootScrollableFrame, "The root scorollable frame is null");
|
|
|
|
|
|
|
|
|
|
if (!IsProperAncestorFrame(rootScrollFrame, aFrame))
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2006-11-01 16:56:48 +03:00
|
|
|
|
|
|
|
|
|
nsIFrame* rootScrolledFrame = rootScrollableFrame->GetScrolledFrame();
|
|
|
|
|
return !(rootScrolledFrame == aFrame ||
|
|
|
|
|
IsProperAncestorFrame(rootScrolledFrame, aFrame));
|
|
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
2014-07-24 21:03:26 +04:00
|
|
|
|
static nscoord AddPercents(nsLayoutUtils::IntrinsicISizeType aType,
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
nscoord aCurrent, float aPercent)
|
|
|
|
|
{
|
|
|
|
|
nscoord result = aCurrent;
|
2014-07-24 21:03:26 +04:00
|
|
|
|
if (aPercent > 0.0f && aType == nsLayoutUtils::PREF_ISIZE) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
// 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;
|
|
|
|
|
}
|
2006-12-17 17:06:42 +03:00
|
|
|
|
|
2010-08-25 14:17:55 +04:00
|
|
|
|
// Use only for widths/heights (or their min/max), since it clamps
|
|
|
|
|
// negative calc() results to 0.
|
2011-09-29 10:19:26 +04:00
|
|
|
|
static bool GetAbsoluteCoord(const nsStyleCoord& aStyle, nscoord& aResult)
|
2008-07-18 03:37:12 +04:00
|
|
|
|
{
|
2010-08-11 23:32:53 +04:00
|
|
|
|
if (aStyle.IsCalcUnit()) {
|
|
|
|
|
if (aStyle.CalcHasPercent()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2010-08-11 23:32:53 +04:00
|
|
|
|
}
|
|
|
|
|
// If it has no percents, we can pass 0 for the percentage basis.
|
|
|
|
|
aResult = nsRuleNode::ComputeComputedCalc(aStyle, 0);
|
2010-08-25 14:17:55 +04:00
|
|
|
|
if (aResult < 0)
|
|
|
|
|
aResult = 0;
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true;
|
2010-08-11 23:32:53 +04:00
|
|
|
|
}
|
|
|
|
|
|
2008-07-18 03:37:12 +04:00
|
|
|
|
if (eStyleUnit_Coord != aStyle.GetUnit())
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2010-04-27 20:15:01 +04:00
|
|
|
|
|
2008-07-18 03:37:12 +04:00
|
|
|
|
aResult = aStyle.GetCoordValue();
|
2010-08-25 14:17:55 +04:00
|
|
|
|
NS_ASSERTION(aResult >= 0, "negative widths not allowed");
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true;
|
2008-07-18 03:37:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-10-18 01:01:56 +04:00
|
|
|
|
// Only call on style coords for which GetAbsoluteCoord returned false.
|
2011-09-29 10:19:26 +04:00
|
|
|
|
static bool
|
2014-12-04 11:57:17 +03:00
|
|
|
|
GetPercentBSize(const nsStyleCoord& aStyle,
|
2007-06-12 22:27:09 +04:00
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
|
nscoord& aResult)
|
|
|
|
|
{
|
2012-10-18 01:01:56 +04:00
|
|
|
|
if (eStyleUnit_Percent != aStyle.GetUnit() &&
|
|
|
|
|
!aStyle.IsCalcUnit())
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2007-06-12 22:27:09 +04:00
|
|
|
|
|
2012-10-18 01:01:56 +04:00
|
|
|
|
MOZ_ASSERT(!aStyle.IsCalcUnit() || aStyle.CalcHasPercent(),
|
|
|
|
|
"GetAbsoluteCoord should have handled this");
|
|
|
|
|
|
2011-05-12 08:04:30 +04:00
|
|
|
|
nsIFrame *f = aFrame->GetContainingBlock();
|
2007-06-12 22:27:09 +04:00
|
|
|
|
if (!f) {
|
|
|
|
|
NS_NOTREACHED("top of frame tree not a containing block");
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2007-06-12 22:27:09 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-13 01:24:17 +04:00
|
|
|
|
// During reflow, nsHTMLScrollFrame::ReflowScrolledFrame uses
|
|
|
|
|
// SetComputedHeight on the reflow state for its child to propagate its
|
|
|
|
|
// computed height to the scrolled content. So here we skip to the scroll
|
|
|
|
|
// frame that contains this scrolled content in order to get the same
|
|
|
|
|
// behavior as layout when computing percentage heights.
|
|
|
|
|
if (f->StyleContext()->GetPseudo() == nsCSSAnonBoxes::scrolledContent) {
|
|
|
|
|
f = f->GetParent();
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-11 13:37:46 +03:00
|
|
|
|
WritingMode wm = f->GetWritingMode();
|
2014-12-04 11:57:17 +03:00
|
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
|
const nsStylePosition *pos = f->StylePosition();
|
2015-05-11 13:37:46 +03:00
|
|
|
|
const nsStyleCoord& bSizeCoord = pos->BSize(wm);
|
2007-06-12 22:27:09 +04:00
|
|
|
|
nscoord h;
|
2014-12-04 11:57:17 +03:00
|
|
|
|
if (!GetAbsoluteCoord(bSizeCoord, h) &&
|
|
|
|
|
!GetPercentBSize(bSizeCoord, f, h)) {
|
|
|
|
|
NS_ASSERTION(bSizeCoord.GetUnit() == eStyleUnit_Auto ||
|
|
|
|
|
bSizeCoord.HasPercent(),
|
|
|
|
|
"unknown block-size unit");
|
2010-08-06 01:59:36 +04: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 18:59:28 +04:00
|
|
|
|
return false;
|
2010-08-06 01:59:36 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-04 11:57:17 +03:00
|
|
|
|
NS_ASSERTION(bSizeCoord.GetUnit() == eStyleUnit_Auto,
|
|
|
|
|
"Unexpected block-size unit for viewport or canvas or page-content");
|
2010-08-06 01:59:36 +04:00
|
|
|
|
// For the viewport, canvas, and page-content kids, the percentage
|
2015-05-11 13:37:46 +03:00
|
|
|
|
// basis is just the parent block-size.
|
|
|
|
|
h = f->BSize(wm);
|
2010-08-06 01:59:36 +04:00
|
|
|
|
if (h == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
|
// We don't have a percentage basis after all
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2010-08-06 01:59:36 +04:00
|
|
|
|
}
|
2007-06-12 22:27:09 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-11 13:37:46 +03:00
|
|
|
|
const nsStyleCoord& maxBSizeCoord = pos->MaxBSize(wm);
|
2014-12-04 11:57:17 +03:00
|
|
|
|
|
2007-06-12 22:27:09 +04:00
|
|
|
|
nscoord maxh;
|
2014-12-04 11:57:17 +03:00
|
|
|
|
if (GetAbsoluteCoord(maxBSizeCoord, maxh) ||
|
|
|
|
|
GetPercentBSize(maxBSizeCoord, f, maxh)) {
|
2007-06-12 22:27:09 +04:00
|
|
|
|
if (maxh < h)
|
|
|
|
|
h = maxh;
|
|
|
|
|
} else {
|
2014-12-04 11:57:17 +03:00
|
|
|
|
NS_ASSERTION(maxBSizeCoord.GetUnit() == eStyleUnit_None ||
|
|
|
|
|
maxBSizeCoord.HasPercent(),
|
|
|
|
|
"unknown max block-size unit");
|
2007-06-12 22:27:09 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-11 13:37:46 +03:00
|
|
|
|
const nsStyleCoord& minBSizeCoord = pos->MinBSize(wm);
|
2014-12-04 11:57:17 +03:00
|
|
|
|
|
2007-06-12 22:27:09 +04:00
|
|
|
|
nscoord minh;
|
2014-12-04 11:57:17 +03:00
|
|
|
|
if (GetAbsoluteCoord(minBSizeCoord, minh) ||
|
|
|
|
|
GetPercentBSize(minBSizeCoord, f, minh)) {
|
2007-06-12 22:27:09 +04:00
|
|
|
|
if (minh > h)
|
|
|
|
|
h = minh;
|
|
|
|
|
} else {
|
2014-12-04 11:57:17 +03:00
|
|
|
|
NS_ASSERTION(minBSizeCoord.HasPercent() ||
|
|
|
|
|
minBSizeCoord.GetUnit() == eStyleUnit_Auto,
|
|
|
|
|
"unknown min block-size unit");
|
2007-06-12 22:27:09 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-10-18 01:01:56 +04:00
|
|
|
|
if (aStyle.IsCalcUnit()) {
|
2013-01-15 16:22:03 +04:00
|
|
|
|
aResult = std::max(nsRuleNode::ComputeComputedCalc(aStyle, h), 0);
|
2012-10-18 01:01:56 +04:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-12 22:27:09 +04:00
|
|
|
|
aResult = NSToCoordRound(aStyle.GetPercentValue() * h);
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true;
|
2007-06-12 22:27:09 +04:00
|
|
|
|
}
|
|
|
|
|
|
2007-11-15 21:10:31 +03: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-04 03:11:00 +04:00
|
|
|
|
// intrinsic widths.
|
|
|
|
|
enum eWidthProperty { PROP_WIDTH, PROP_MAX_WIDTH, PROP_MIN_WIDTH };
|
2011-09-29 10:19:26 +04:00
|
|
|
|
static bool
|
2007-05-04 03:11:00 +04:00
|
|
|
|
GetIntrinsicCoord(const nsStyleCoord& aStyle,
|
2011-04-08 05:04:40 +04:00
|
|
|
|
nsRenderingContext* aRenderingContext,
|
2007-05-04 03:11:00 +04: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 18:59:28 +04:00
|
|
|
|
return false;
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t val = aStyle.GetIntValue();
|
2007-11-15 21:10:31 +03: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-04 03:11:00 +04:00
|
|
|
|
"unexpected enumerated value for width property");
|
2007-11-15 21:10:31 +03:00
|
|
|
|
if (val == NS_STYLE_WIDTH_AVAILABLE)
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2007-11-15 21:10:31 +03:00
|
|
|
|
if (val == NS_STYLE_WIDTH_FIT_CONTENT) {
|
2007-05-04 03:11:00 +04:00
|
|
|
|
if (aProperty == PROP_WIDTH)
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false; // handle like 'width: auto'
|
2007-05-04 03:11:00 +04:00
|
|
|
|
if (aProperty == PROP_MAX_WIDTH)
|
2007-11-15 21:10:31 +03:00
|
|
|
|
// constrain large 'width' values down to -moz-max-content
|
|
|
|
|
val = NS_STYLE_WIDTH_MAX_CONTENT;
|
2007-05-04 03:11:00 +04:00
|
|
|
|
else
|
2007-11-15 21:10:31 +03:00
|
|
|
|
// constrain small 'width' or 'max-width' values up to -moz-min-content
|
|
|
|
|
val = NS_STYLE_WIDTH_MIN_CONTENT;
|
2007-05-04 03:11:00 +04:00
|
|
|
|
}
|
|
|
|
|
|
2007-11-15 21:10:31 +03:00
|
|
|
|
NS_ASSERTION(val == NS_STYLE_WIDTH_MAX_CONTENT ||
|
|
|
|
|
val == NS_STYLE_WIDTH_MIN_CONTENT,
|
2007-05-04 03:11:00 +04:00
|
|
|
|
"should have reduced everything remaining to one of these");
|
2012-01-25 05:21:29 +04:00
|
|
|
|
|
|
|
|
|
// If aFrame is a container for font size inflation, then shrink
|
|
|
|
|
// wrapping inside of it should not apply font size inflation.
|
2012-05-21 09:18:27 +04:00
|
|
|
|
AutoMaybeDisableFontInflation an(aFrame);
|
2012-01-25 05:21:29 +04:00
|
|
|
|
|
2007-11-15 21:10:31 +03:00
|
|
|
|
if (val == NS_STYLE_WIDTH_MAX_CONTENT)
|
2014-07-24 21:03:25 +04:00
|
|
|
|
aResult = aFrame->GetPrefISize(aRenderingContext);
|
2007-05-04 03:11:00 +04:00
|
|
|
|
else
|
2014-07-24 21:03:25 +04:00
|
|
|
|
aResult = aFrame->GetMinISize(aRenderingContext);
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true;
|
2007-05-04 03:11:00 +04:00
|
|
|
|
}
|
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
#undef DEBUG_INTRINSIC_WIDTH
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG_INTRINSIC_WIDTH
|
2012-08-22 19:56:38 +04:00
|
|
|
|
static int32_t gNoiseIndent = 0;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
#endif
|
|
|
|
|
|
2015-06-16 14:21:03 +03:00
|
|
|
|
/**
|
|
|
|
|
* Add aOffsets which describes what to add on outside of the content box
|
|
|
|
|
* aContentSize (controlled by 'box-sizing') and apply min/max properties.
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* @param aContentSize the content size calculated so far
|
|
|
|
|
(@see IntrinsicForContainer)
|
|
|
|
|
* @param aContentMinSize ditto min content size
|
|
|
|
|
* @param aStyleSize a 'width' or 'height' property value
|
|
|
|
|
* @param aFixedMinSize if aStyleMinSize is a definite size then this points to
|
|
|
|
|
* the value, otherwise nullptr
|
|
|
|
|
* @param aStyleMinSize a 'min-width' or 'min-height' property value
|
|
|
|
|
* @param aFixedMaxSize if aStyleMaxSize is a definite size then this points to
|
|
|
|
|
* the value, otherwise nullptr
|
|
|
|
|
* @param aStyleMaxSize a 'max-width' or 'max-height' property value
|
|
|
|
|
* @param aFlags same as for IntrinsicForContainer
|
|
|
|
|
* @param aContainerWM the container's WM
|
|
|
|
|
*/
|
2015-06-16 14:21:03 +03:00
|
|
|
|
static nscoord
|
|
|
|
|
AddIntrinsicSizeOffset(nsRenderingContext* aRenderingContext,
|
|
|
|
|
nsIFrame* aFrame,
|
2015-06-16 14:21:03 +03:00
|
|
|
|
const nsIFrame::IntrinsicISizeOffsetData& aOffsets,
|
2015-06-16 14:21:03 +03:00
|
|
|
|
nsLayoutUtils::IntrinsicISizeType aType,
|
2015-06-16 14:21:03 +03:00
|
|
|
|
uint8_t aBoxSizing,
|
2015-06-16 14:21:03 +03:00
|
|
|
|
nscoord aContentSize,
|
|
|
|
|
nscoord aContentMinSize,
|
2015-06-16 14:21:03 +03:00
|
|
|
|
const nsStyleCoord& aStyleSize,
|
2015-06-16 14:21:03 +03:00
|
|
|
|
const nscoord* aFixedMinSize,
|
2015-06-16 14:21:03 +03:00
|
|
|
|
const nsStyleCoord& aStyleMinSize,
|
2015-06-16 14:21:03 +03:00
|
|
|
|
const nscoord* aFixedMaxSize,
|
2015-06-16 14:21:03 +03:00
|
|
|
|
const nsStyleCoord& aStyleMaxSize,
|
2015-06-16 14:21:03 +03:00
|
|
|
|
uint32_t aFlags,
|
2015-06-16 14:21:04 +03:00
|
|
|
|
PhysicalAxis aAxis)
|
2015-06-16 14:21:03 +03:00
|
|
|
|
{
|
2015-06-16 14:21:03 +03:00
|
|
|
|
nscoord result = aContentSize;
|
|
|
|
|
nscoord min = aContentMinSize;
|
2015-06-16 14:21:03 +03:00
|
|
|
|
nscoord coordOutsideSize = 0;
|
|
|
|
|
float pctOutsideSize = 0;
|
2015-06-16 14:21:03 +03:00
|
|
|
|
float pctTotal = 0.0f;
|
|
|
|
|
|
|
|
|
|
if (!(aFlags & nsLayoutUtils::IGNORE_PADDING)) {
|
2015-06-16 14:21:03 +03:00
|
|
|
|
coordOutsideSize += aOffsets.hPadding;
|
|
|
|
|
pctOutsideSize += aOffsets.hPctPadding;
|
2015-06-16 14:21:03 +03:00
|
|
|
|
|
2015-06-16 14:21:03 +03:00
|
|
|
|
if (aBoxSizing == NS_STYLE_BOX_SIZING_PADDING) {
|
2015-06-16 14:21:03 +03:00
|
|
|
|
min += coordOutsideSize;
|
|
|
|
|
result = NSCoordSaturatingAdd(result, coordOutsideSize);
|
|
|
|
|
pctTotal += pctOutsideSize;
|
2015-06-16 14:21:03 +03:00
|
|
|
|
|
2015-06-16 14:21:03 +03:00
|
|
|
|
coordOutsideSize = 0;
|
|
|
|
|
pctOutsideSize = 0.0f;
|
2015-06-16 14:21:03 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-16 14:21:03 +03:00
|
|
|
|
coordOutsideSize += aOffsets.hBorder;
|
2015-06-16 14:21:03 +03:00
|
|
|
|
|
2015-06-16 14:21:03 +03:00
|
|
|
|
if (aBoxSizing == NS_STYLE_BOX_SIZING_BORDER) {
|
2015-06-16 14:21:03 +03:00
|
|
|
|
min += coordOutsideSize;
|
|
|
|
|
result = NSCoordSaturatingAdd(result, coordOutsideSize);
|
|
|
|
|
pctTotal += pctOutsideSize;
|
2015-06-16 14:21:03 +03:00
|
|
|
|
|
2015-06-16 14:21:03 +03:00
|
|
|
|
coordOutsideSize = 0;
|
|
|
|
|
pctOutsideSize = 0.0f;
|
2015-06-16 14:21:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-16 14:21:03 +03:00
|
|
|
|
coordOutsideSize += aOffsets.hMargin;
|
|
|
|
|
pctOutsideSize += aOffsets.hPctMargin;
|
2015-06-16 14:21:03 +03:00
|
|
|
|
|
2015-06-16 14:21:03 +03:00
|
|
|
|
min += coordOutsideSize;
|
|
|
|
|
result = NSCoordSaturatingAdd(result, coordOutsideSize);
|
|
|
|
|
pctTotal += pctOutsideSize;
|
2015-06-16 14:21:03 +03:00
|
|
|
|
|
2015-06-16 14:21:03 +03:00
|
|
|
|
nscoord size;
|
|
|
|
|
if (GetAbsoluteCoord(aStyleSize, size) ||
|
2015-06-16 14:21:03 +03:00
|
|
|
|
GetIntrinsicCoord(aStyleSize, aRenderingContext, aFrame,
|
2015-06-16 14:21:03 +03:00
|
|
|
|
PROP_WIDTH, size)) {
|
|
|
|
|
result = AddPercents(aType, size + coordOutsideSize, pctOutsideSize);
|
2015-06-16 14:21:03 +03:00
|
|
|
|
} else if (aType == nsLayoutUtils::MIN_ISIZE &&
|
|
|
|
|
// The only cases of coord-percent-calc() units that
|
|
|
|
|
// GetAbsoluteCoord didn't handle are percent and calc()s
|
|
|
|
|
// containing percent.
|
|
|
|
|
aStyleSize.IsCoordPercentCalcUnit() &&
|
|
|
|
|
aFrame->IsFrameOfType(nsIFrame::eReplaced)) {
|
2015-06-16 14:21:03 +03:00
|
|
|
|
// A percentage width on replaced elements means they can shrink to 0.
|
|
|
|
|
result = 0; // let |min| handle padding/border/margin
|
2015-06-16 14:21:03 +03:00
|
|
|
|
} else {
|
2015-06-16 14:21:03 +03: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.
|
|
|
|
|
result = AddPercents(aType, result, pctTotal);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-16 14:21:03 +03:00
|
|
|
|
nscoord maxSize = aFixedMaxSize ? *aFixedMaxSize : 0;
|
|
|
|
|
if (aFixedMaxSize ||
|
2015-06-16 14:21:03 +03:00
|
|
|
|
GetIntrinsicCoord(aStyleMaxSize, aRenderingContext, aFrame,
|
2015-06-16 14:21:03 +03:00
|
|
|
|
PROP_MAX_WIDTH, maxSize)) {
|
|
|
|
|
maxSize = AddPercents(aType, maxSize + coordOutsideSize, pctOutsideSize);
|
2015-06-16 14:21:03 +03:00
|
|
|
|
if (result > maxSize) {
|
2015-06-16 14:21:03 +03:00
|
|
|
|
result = maxSize;
|
2015-06-16 14:21:03 +03:00
|
|
|
|
}
|
2015-06-16 14:21:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-16 14:21:03 +03:00
|
|
|
|
nscoord minSize = aFixedMinSize ? *aFixedMinSize : 0;
|
|
|
|
|
if (aFixedMinSize ||
|
2015-06-16 14:21:03 +03:00
|
|
|
|
GetIntrinsicCoord(aStyleMinSize, aRenderingContext, aFrame,
|
2015-06-16 14:21:03 +03:00
|
|
|
|
PROP_MIN_WIDTH, minSize)) {
|
|
|
|
|
minSize = AddPercents(aType, minSize + coordOutsideSize, pctOutsideSize);
|
2015-06-16 14:21:03 +03:00
|
|
|
|
if (result < minSize) {
|
2015-06-16 14:21:03 +03:00
|
|
|
|
result = minSize;
|
2015-06-16 14:21:03 +03:00
|
|
|
|
}
|
2015-06-16 14:21:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
min = AddPercents(aType, min, pctTotal);
|
2015-06-16 14:21:03 +03:00
|
|
|
|
if (result < min) {
|
2015-06-16 14:21:03 +03:00
|
|
|
|
result = min;
|
2015-06-16 14:21:03 +03:00
|
|
|
|
}
|
2015-06-16 14:21:03 +03:00
|
|
|
|
|
2015-06-16 14:21:03 +03:00
|
|
|
|
const nsStyleDisplay* disp = aFrame->StyleDisplay();
|
2015-06-16 14:21:03 +03:00
|
|
|
|
if (aFrame->IsThemed(disp)) {
|
2015-06-16 14:21:03 +03:00
|
|
|
|
LayoutDeviceIntSize devSize;
|
2015-06-16 14:21:03 +03:00
|
|
|
|
bool canOverride = true;
|
2015-06-16 14:21:03 +03:00
|
|
|
|
nsPresContext* pc = aFrame->PresContext();
|
|
|
|
|
pc->GetTheme()->GetMinimumWidgetSize(pc, aFrame, disp->mAppearance,
|
|
|
|
|
&devSize, &canOverride);
|
2015-06-16 14:21:03 +03:00
|
|
|
|
nscoord themeSize =
|
2015-06-16 14:21:04 +03:00
|
|
|
|
pc->DevPixelsToAppUnits(aAxis == eAxisVertical ? devSize.height
|
|
|
|
|
: devSize.width);
|
2015-06-16 14:21:03 +03:00
|
|
|
|
// GetMinimumWidgetSize() returns a border-box width.
|
2015-06-16 14:21:03 +03:00
|
|
|
|
themeSize += aOffsets.hMargin;
|
|
|
|
|
themeSize = AddPercents(aType, themeSize, aOffsets.hPctMargin);
|
2015-06-16 14:21:03 +03:00
|
|
|
|
|
2015-06-16 14:21:03 +03:00
|
|
|
|
if (themeSize > result || !canOverride) {
|
|
|
|
|
result = themeSize;
|
2015-06-16 14:21:03 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-18 03:24:53 +03:00
|
|
|
|
static void
|
|
|
|
|
AddStateBitToAncestors(nsIFrame* aFrame, nsFrameState aBit)
|
|
|
|
|
{
|
|
|
|
|
for (nsIFrame* f = aFrame; f; f = f->GetParent()) {
|
|
|
|
|
if (f->HasAnyStateBits(aBit)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
f->AddStateBits(aBit);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
/* static */ nscoord
|
2015-06-16 14:21:04 +03:00
|
|
|
|
nsLayoutUtils::IntrinsicForAxis(PhysicalAxis aAxis,
|
|
|
|
|
nsRenderingContext* aRenderingContext,
|
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
|
IntrinsicISizeType aType,
|
|
|
|
|
uint32_t aFlags)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
{
|
|
|
|
|
NS_PRECONDITION(aFrame, "null frame");
|
2014-12-04 11:57:17 +03:00
|
|
|
|
NS_PRECONDITION(aFrame->GetParent(),
|
2015-06-16 14:21:04 +03:00
|
|
|
|
"IntrinsicForAxis called on frame not in tree");
|
2014-07-24 21:03:26 +04:00
|
|
|
|
NS_PRECONDITION(aType == MIN_ISIZE || aType == PREF_ISIZE, "bad type");
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
2015-06-16 14:21:04 +03:00
|
|
|
|
const bool horizontalAxis = MOZ_LIKELY(aAxis == eAxisHorizontal);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
#ifdef DEBUG_INTRINSIC_WIDTH
|
2013-11-24 02:44:18 +04:00
|
|
|
|
nsFrame::IndentBy(stderr, gNoiseIndent);
|
|
|
|
|
static_cast<nsFrame*>(aFrame)->ListTag(stderr);
|
2015-06-16 14:21:04 +03:00
|
|
|
|
printf_stderr(" %s %s intrinsic size for container:\n",
|
|
|
|
|
aType == MIN_ISIZE ? "min" : "pref",
|
|
|
|
|
horizontalAxis ? "horizontal" : "vertical");
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
#endif
|
|
|
|
|
|
2012-01-25 05:21:29 +04:00
|
|
|
|
// If aFrame is a container for font size inflation, then shrink
|
|
|
|
|
// wrapping inside of it should not apply font size inflation.
|
2012-05-21 09:18:27 +04:00
|
|
|
|
AutoMaybeDisableFontInflation an(aFrame);
|
2012-01-25 05:21:29 +04:00
|
|
|
|
|
2014-12-04 11:57:17 +03:00
|
|
|
|
// We want the size this frame will contribute to the parent's inline-size,
|
|
|
|
|
// so we work in the parent's writing mode; but if aFrame is orthogonal to
|
|
|
|
|
// its parent, we'll need to look at its BSize instead of min/pref-ISize.
|
2015-06-16 14:21:03 +03:00
|
|
|
|
const nsStylePosition* stylePos = aFrame->StylePosition();
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint8_t boxSizing = stylePos->mBoxSizing;
|
2014-12-04 11:57:17 +03:00
|
|
|
|
|
2015-06-16 14:21:04 +03:00
|
|
|
|
const nsStyleCoord& styleISize =
|
|
|
|
|
horizontalAxis ? stylePos->mWidth : stylePos->mHeight;
|
|
|
|
|
const nsStyleCoord& styleMinISize =
|
|
|
|
|
horizontalAxis ? stylePos->mMinWidth : stylePos->mMinHeight;
|
|
|
|
|
const nsStyleCoord& styleMaxISize =
|
|
|
|
|
horizontalAxis ? stylePos->mMaxWidth : stylePos->mMaxHeight;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
2014-12-04 11:57:17 +03:00
|
|
|
|
nscoord maxISize;
|
|
|
|
|
bool haveFixedMaxISize = GetAbsoluteCoord(styleMaxISize, maxISize);
|
|
|
|
|
nscoord minISize;
|
2014-07-22 19:24:34 +04:00
|
|
|
|
|
|
|
|
|
// Treat "min-width: auto" as 0.
|
2014-12-04 11:57:17 +03:00
|
|
|
|
bool haveFixedMinISize;
|
|
|
|
|
if (eStyleUnit_Auto == styleMinISize.GetUnit()) {
|
2014-07-22 19:24:34 +04:00
|
|
|
|
// 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.
|
2014-12-04 11:57:17 +03:00
|
|
|
|
minISize = 0;
|
|
|
|
|
haveFixedMinISize = true;
|
2014-07-22 19:24:34 +04:00
|
|
|
|
} else {
|
2014-12-04 11:57:17 +03:00
|
|
|
|
haveFixedMinISize = GetAbsoluteCoord(styleMinISize, minISize);
|
2014-07-22 19:24:34 +04:00
|
|
|
|
}
|
2010-08-25 14:17:56 +04:00
|
|
|
|
|
2015-06-16 14:21:04 +03:00
|
|
|
|
PhysicalAxis ourInlineAxis =
|
|
|
|
|
aFrame->GetWritingMode().PhysicalAxis(eLogicalAxisInline);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
// If we have a specified width (or a specified 'min-width' greater
|
|
|
|
|
// than the specified 'max-width', which works out to the same thing),
|
2012-11-21 20:19:37 +04:00
|
|
|
|
// don't even bother getting the frame's intrinsic width, because in
|
2014-12-04 11:57:17 +03:00
|
|
|
|
// this case GetAbsoluteCoord(styleISize, w) will always succeed, so
|
2012-11-21 20:19:37 +04:00
|
|
|
|
// we'll never need the intrinsic dimensions.
|
2014-12-04 11:57:17 +03:00
|
|
|
|
if (styleISize.GetUnit() == eStyleUnit_Enumerated &&
|
|
|
|
|
(styleISize.GetIntValue() == NS_STYLE_WIDTH_MAX_CONTENT ||
|
|
|
|
|
styleISize.GetIntValue() == NS_STYLE_WIDTH_MIN_CONTENT)) {
|
2007-11-15 21:10:31 +03:00
|
|
|
|
// -moz-fit-content and -moz-available enumerated widths compute intrinsic
|
2007-05-04 03:11:00 +04:00
|
|
|
|
// widths just like auto.
|
2007-11-15 21:10:31 +03:00
|
|
|
|
// For -moz-max-content and -moz-min-content, we handle them like
|
2014-02-06 23:32:05 +04:00
|
|
|
|
// specified widths, but ignore box-sizing.
|
2007-05-04 03:11:00 +04:00
|
|
|
|
boxSizing = NS_STYLE_BOX_SIZING_CONTENT;
|
2014-12-04 11:57:17 +03:00
|
|
|
|
} else if (!styleISize.ConvertsToLength() &&
|
|
|
|
|
!(haveFixedMinISize && haveFixedMaxISize && maxISize <= minISize)) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
#ifdef DEBUG_INTRINSIC_WIDTH
|
|
|
|
|
++gNoiseIndent;
|
|
|
|
|
#endif
|
2015-06-16 14:21:04 +03:00
|
|
|
|
if (MOZ_UNLIKELY(aAxis != ourInlineAxis)) {
|
|
|
|
|
// We need aFrame's block-dir size.
|
2014-12-04 11:57:17 +03:00
|
|
|
|
// XXX Unfortunately, we probably don't know this yet, so this is wrong...
|
|
|
|
|
// but it's not clear what we should do. If aFrame's inline size hasn't
|
|
|
|
|
// been determined yet, we can't necessarily figure out its block size
|
|
|
|
|
// either. For now, authors who put orthogonal elements into things like
|
|
|
|
|
// buttons or table cells may have to explicitly provide sizes rather
|
|
|
|
|
// than expecting intrinsic sizing to work "perfectly" in underspecified
|
|
|
|
|
// cases.
|
|
|
|
|
result = aFrame->BSize();
|
|
|
|
|
} else {
|
|
|
|
|
result = aType == MIN_ISIZE
|
|
|
|
|
? aFrame->GetMinISize(aRenderingContext)
|
|
|
|
|
: aFrame->GetPrefISize(aRenderingContext);
|
|
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
#ifdef DEBUG_INTRINSIC_WIDTH
|
|
|
|
|
--gNoiseIndent;
|
2013-11-24 02:44:18 +04:00
|
|
|
|
nsFrame::IndentBy(stderr, gNoiseIndent);
|
|
|
|
|
static_cast<nsFrame*>(aFrame)->ListTag(stderr);
|
2015-06-16 14:21:04 +03:00
|
|
|
|
printf_stderr(" %s %s intrinsic size from frame is %d.\n",
|
|
|
|
|
aType == MIN_ISIZE ? "min" : "pref",
|
|
|
|
|
horizontalAxis ? "horizontal" : "vertical",
|
|
|
|
|
result);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
#endif
|
2007-06-12 22:27:09 +04:00
|
|
|
|
|
|
|
|
|
// Handle elements with an intrinsic ratio (or size) and a specified
|
|
|
|
|
// height, min-height, or max-height.
|
2014-07-22 19:24:35 +04: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.
|
2015-06-16 14:21:04 +03:00
|
|
|
|
const nsStyleCoord& styleBSize =
|
|
|
|
|
horizontalAxis ? stylePos->mHeight : stylePos->mWidth;
|
|
|
|
|
const nsStyleCoord& styleMinBSize =
|
|
|
|
|
horizontalAxis ? stylePos->mMinHeight : stylePos->mMinWidth;
|
|
|
|
|
const nsStyleCoord& styleMaxBSize =
|
|
|
|
|
horizontalAxis ? stylePos->mMaxHeight : stylePos->mMaxWidth;
|
2014-12-04 11:57:17 +03:00
|
|
|
|
|
|
|
|
|
if (styleBSize.GetUnit() != eStyleUnit_Auto ||
|
|
|
|
|
!(styleMinBSize.GetUnit() == eStyleUnit_Auto ||
|
|
|
|
|
(styleMinBSize.GetUnit() == eStyleUnit_Coord &&
|
|
|
|
|
styleMinBSize.GetCoordValue() == 0)) ||
|
|
|
|
|
styleMaxBSize.GetUnit() != eStyleUnit_None) {
|
|
|
|
|
|
2015-06-16 14:21:04 +03:00
|
|
|
|
nsSize ratio(aFrame->GetIntrinsicRatio());
|
|
|
|
|
nscoord ratioISize = (horizontalAxis ? ratio.width : ratio.height);
|
|
|
|
|
nscoord ratioBSize = (horizontalAxis ? ratio.height : ratio.width);
|
|
|
|
|
if (ratioBSize != 0) {
|
2015-07-18 03:24:53 +03:00
|
|
|
|
AddStateBitToAncestors(aFrame,
|
|
|
|
|
NS_FRAME_DESCENDANT_INTRINSIC_ISIZE_DEPENDS_ON_BSIZE);
|
|
|
|
|
|
2014-12-04 11:57:17 +03:00
|
|
|
|
nscoord bSizeTakenByBoxSizing = 0;
|
2015-05-29 22:16:53 +03:00
|
|
|
|
switch (boxSizing) {
|
|
|
|
|
case NS_STYLE_BOX_SIZING_BORDER: {
|
2013-02-17 01:51:02 +04:00
|
|
|
|
const nsStyleBorder* styleBorder = aFrame->StyleBorder();
|
2014-12-04 11:57:17 +03:00
|
|
|
|
bSizeTakenByBoxSizing +=
|
2015-06-16 14:21:04 +03:00
|
|
|
|
horizontalAxis ? styleBorder->GetComputedBorder().TopBottom()
|
|
|
|
|
: styleBorder->GetComputedBorder().LeftRight();
|
2015-05-29 22:16:53 +03:00
|
|
|
|
// fall through
|
|
|
|
|
}
|
|
|
|
|
case NS_STYLE_BOX_SIZING_PADDING: {
|
2013-10-23 02:46:40 +04:00
|
|
|
|
if (!(aFlags & IGNORE_PADDING)) {
|
2015-05-11 13:37:46 +03:00
|
|
|
|
const nsStyleSides& stylePadding =
|
|
|
|
|
aFrame->StylePadding()->mPadding;
|
2015-06-16 14:21:04 +03:00
|
|
|
|
const nsStyleCoord& paddingStart =
|
|
|
|
|
stylePadding.Get(horizontalAxis ? NS_SIDE_TOP : NS_SIDE_LEFT);
|
|
|
|
|
const nsStyleCoord& paddingEnd =
|
|
|
|
|
stylePadding.Get(horizontalAxis ? NS_SIDE_BOTTOM : NS_SIDE_RIGHT);
|
2013-10-23 02:46:40 +04:00
|
|
|
|
nscoord pad;
|
2014-12-04 11:57:17 +03:00
|
|
|
|
if (GetAbsoluteCoord(paddingStart, pad) ||
|
|
|
|
|
GetPercentBSize(paddingStart, aFrame, pad)) {
|
|
|
|
|
bSizeTakenByBoxSizing += pad;
|
2013-10-23 02:46:40 +04:00
|
|
|
|
}
|
2014-12-04 11:57:17 +03:00
|
|
|
|
if (GetAbsoluteCoord(paddingEnd, pad) ||
|
|
|
|
|
GetPercentBSize(paddingEnd, aFrame, pad)) {
|
|
|
|
|
bSizeTakenByBoxSizing += pad;
|
2013-10-23 02:46:40 +04:00
|
|
|
|
}
|
2012-10-16 07:12:03 +04:00
|
|
|
|
}
|
2015-05-29 22:16:53 +03:00
|
|
|
|
// fall through
|
|
|
|
|
}
|
|
|
|
|
case NS_STYLE_BOX_SIZING_CONTENT:
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2012-10-16 07:12:03 +04:00
|
|
|
|
}
|
2007-06-12 22:27:09 +04:00
|
|
|
|
|
|
|
|
|
nscoord h;
|
2014-12-04 11:57:17 +03:00
|
|
|
|
if (GetAbsoluteCoord(styleBSize, h) ||
|
|
|
|
|
GetPercentBSize(styleBSize, aFrame, h)) {
|
|
|
|
|
h = std::max(0, h - bSizeTakenByBoxSizing);
|
2015-06-16 14:21:04 +03:00
|
|
|
|
result = NSCoordMulDiv(h, ratioISize, ratioBSize);
|
2007-06-12 22:27:09 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-04 11:57:17 +03:00
|
|
|
|
if (GetAbsoluteCoord(styleMaxBSize, h) ||
|
|
|
|
|
GetPercentBSize(styleMaxBSize, aFrame, h)) {
|
|
|
|
|
h = std::max(0, h - bSizeTakenByBoxSizing);
|
2015-06-16 14:21:04 +03:00
|
|
|
|
nscoord maxISize = NSCoordMulDiv(h, ratioISize, ratioBSize);
|
2014-12-04 11:57:17 +03:00
|
|
|
|
if (maxISize < result)
|
|
|
|
|
result = maxISize;
|
2007-06-12 22:27:09 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-04 11:57:17 +03:00
|
|
|
|
if (GetAbsoluteCoord(styleMinBSize, h) ||
|
|
|
|
|
GetPercentBSize(styleMinBSize, aFrame, h)) {
|
|
|
|
|
h = std::max(0, h - bSizeTakenByBoxSizing);
|
2015-06-16 14:21:04 +03:00
|
|
|
|
nscoord minISize = NSCoordMulDiv(h, ratioISize, ratioBSize);
|
2014-12-04 11:57:17 +03:00
|
|
|
|
if (minISize > result)
|
|
|
|
|
result = minISize;
|
2007-06-12 22:27:09 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
}
|
2010-04-27 20:15:01 +04:00
|
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
|
if (aFrame->GetType() == nsGkAtoms::tableFrame) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
// Tables can't shrink smaller than their intrinsic minimum width,
|
|
|
|
|
// no matter what.
|
2014-07-24 21:03:25 +04:00
|
|
|
|
min = aFrame->GetMinISize(aRenderingContext);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-16 14:21:04 +03:00
|
|
|
|
nsIFrame::IntrinsicISizeOffsetData offsets =
|
2015-06-16 14:21:04 +03:00
|
|
|
|
MOZ_LIKELY(aAxis == ourInlineAxis) ? aFrame->IntrinsicISizeOffsets()
|
|
|
|
|
: aFrame->IntrinsicBSizeOffsets();
|
2015-06-16 14:21:03 +03:00
|
|
|
|
result = AddIntrinsicSizeOffset(aRenderingContext, aFrame, offsets, aType,
|
|
|
|
|
boxSizing, result, min, styleISize,
|
2015-06-16 14:21:03 +03:00
|
|
|
|
haveFixedMinISize ? &minISize : nullptr,
|
|
|
|
|
styleMinISize,
|
|
|
|
|
haveFixedMaxISize ? &maxISize : nullptr,
|
|
|
|
|
styleMaxISize,
|
2015-06-16 14:21:04 +03:00
|
|
|
|
aFlags, aAxis);
|
2007-01-18 01:31:07 +03:00
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
#ifdef DEBUG_INTRINSIC_WIDTH
|
2013-11-24 02:44:18 +04:00
|
|
|
|
nsFrame::IndentBy(stderr, gNoiseIndent);
|
|
|
|
|
static_cast<nsFrame*>(aFrame)->ListTag(stderr);
|
2015-06-16 14:21:04 +03:00
|
|
|
|
printf_stderr(" %s %s intrinsic size for container is %d twips.\n",
|
|
|
|
|
aType == MIN_ISIZE ? "min" : "pref",
|
|
|
|
|
horizontalAxis ? "horizontal" : "vertical",
|
|
|
|
|
result);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-16 14:21:04 +03:00
|
|
|
|
/* static */ nscoord
|
|
|
|
|
nsLayoutUtils::IntrinsicForContainer(nsRenderingContext* aRenderingContext,
|
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
|
IntrinsicISizeType aType,
|
|
|
|
|
uint32_t aFlags)
|
|
|
|
|
{
|
2015-06-16 14:21:04 +03:00
|
|
|
|
MOZ_ASSERT(aFrame && aFrame->GetParent());
|
|
|
|
|
// We want the size aFrame will contribute to its parent's inline-size.
|
|
|
|
|
PhysicalAxis axis =
|
|
|
|
|
aFrame->GetParent()->GetWritingMode().PhysicalAxis(eLogicalAxisInline);
|
|
|
|
|
return IntrinsicForAxis(axis, aRenderingContext, aFrame, aType, aFlags);
|
2015-06-16 14:21:04 +03:00
|
|
|
|
}
|
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
/* static */ nscoord
|
2013-04-11 18:49:53 +04:00
|
|
|
|
nsLayoutUtils::ComputeCBDependentValue(nscoord aPercentBasis,
|
|
|
|
|
const nsStyleCoord& aCoord)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
{
|
2013-04-11 18:49:53 +04:00
|
|
|
|
NS_WARN_IF_FALSE(aPercentBasis != NS_UNCONSTRAINEDSIZE,
|
|
|
|
|
"have unconstrained width or height; this should only "
|
|
|
|
|
"result from very large sizes, not attempts at intrinsic "
|
|
|
|
|
"size calculation");
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
2010-08-25 14:17:55 +04:00
|
|
|
|
if (aCoord.IsCoordPercentCalcUnit()) {
|
2013-04-11 18:49:53 +04:00
|
|
|
|
return nsRuleNode::ComputeCoordPercentCalc(aCoord, aPercentBasis);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
}
|
2007-05-11 10:01:31 +04:00
|
|
|
|
NS_ASSERTION(aCoord.GetUnit() == eStyleUnit_None ||
|
2007-05-04 03:11:00 +04:00
|
|
|
|
aCoord.GetUnit() == eStyleUnit_Auto,
|
|
|
|
|
"unexpected width value");
|
2006-12-17 17:06:42 +03:00
|
|
|
|
return 0;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
2007-05-04 03:11:00 +04:00
|
|
|
|
/* static */ nscoord
|
2014-11-27 18:01:11 +03:00
|
|
|
|
nsLayoutUtils::ComputeISizeValue(
|
2011-04-08 05:04:40 +04:00
|
|
|
|
nsRenderingContext* aRenderingContext,
|
2007-05-04 03:11:00 +04:00
|
|
|
|
nsIFrame* aFrame,
|
2014-11-27 18:01:11 +03:00
|
|
|
|
nscoord aContainingBlockISize,
|
2007-05-04 03:11:00 +04:00
|
|
|
|
nscoord aContentEdgeToBoxSizing,
|
|
|
|
|
nscoord aBoxSizingToMarginEdge,
|
|
|
|
|
const nsStyleCoord& aCoord)
|
|
|
|
|
{
|
|
|
|
|
NS_PRECONDITION(aFrame, "non-null frame expected");
|
|
|
|
|
NS_PRECONDITION(aRenderingContext, "non-null rendering context expected");
|
2014-11-27 18:01:11 +03:00
|
|
|
|
NS_WARN_IF_FALSE(aContainingBlockISize != NS_UNCONSTRAINEDSIZE,
|
|
|
|
|
"have unconstrained inline-size; this should only result from "
|
|
|
|
|
"very large sizes, not attempts at intrinsic inline-size "
|
2009-10-29 06:22:28 +03:00
|
|
|
|
"calculation");
|
2014-11-27 18:01:11 +03:00
|
|
|
|
NS_PRECONDITION(aContainingBlockISize >= 0,
|
|
|
|
|
"inline-size less than zero");
|
2007-05-04 03:11:00 +04:00
|
|
|
|
|
|
|
|
|
nscoord result;
|
2010-08-11 23:32:53 +04:00
|
|
|
|
if (aCoord.IsCoordPercentCalcUnit()) {
|
2012-08-08 19:58:26 +04:00
|
|
|
|
result = nsRuleNode::ComputeCoordPercentCalc(aCoord,
|
2014-11-27 18:01:11 +03:00
|
|
|
|
aContainingBlockISize);
|
2010-08-11 23:32:53 +04: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-04 03:11:00 +04:00
|
|
|
|
result -= aContentEdgeToBoxSizing;
|
2012-08-08 19:58:26 +04:00
|
|
|
|
} else {
|
|
|
|
|
MOZ_ASSERT(eStyleUnit_Enumerated == aCoord.GetUnit());
|
2012-01-25 05:21:29 +04:00
|
|
|
|
// If aFrame is a container for font size inflation, then shrink
|
|
|
|
|
// wrapping inside of it should not apply font size inflation.
|
2012-05-21 09:18:27 +04:00
|
|
|
|
AutoMaybeDisableFontInflation an(aFrame);
|
2012-01-25 05:21:29 +04:00
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t val = aCoord.GetIntValue();
|
2007-05-04 03:11:00 +04:00
|
|
|
|
switch (val) {
|
2007-11-15 21:10:31 +03:00
|
|
|
|
case NS_STYLE_WIDTH_MAX_CONTENT:
|
2014-07-24 21:03:25 +04:00
|
|
|
|
result = aFrame->GetPrefISize(aRenderingContext);
|
2014-11-27 18:01:11 +03:00
|
|
|
|
NS_ASSERTION(result >= 0, "inline-size less than zero");
|
2007-05-04 03:11:00 +04:00
|
|
|
|
break;
|
2007-11-15 21:10:31 +03:00
|
|
|
|
case NS_STYLE_WIDTH_MIN_CONTENT:
|
2014-07-24 21:03:25 +04:00
|
|
|
|
result = aFrame->GetMinISize(aRenderingContext);
|
2014-11-27 18:01:11 +03:00
|
|
|
|
NS_ASSERTION(result >= 0, "inline-size less than zero");
|
2007-05-04 03:11:00 +04:00
|
|
|
|
break;
|
2007-11-15 21:10:31 +03:00
|
|
|
|
case NS_STYLE_WIDTH_FIT_CONTENT:
|
2007-05-04 03:11:00 +04:00
|
|
|
|
{
|
2014-07-24 21:03:25 +04:00
|
|
|
|
nscoord pref = aFrame->GetPrefISize(aRenderingContext),
|
|
|
|
|
min = aFrame->GetMinISize(aRenderingContext),
|
2014-11-27 18:01:11 +03:00
|
|
|
|
fill = aContainingBlockISize -
|
2007-05-04 03:11:00 +04:00
|
|
|
|
(aBoxSizingToMarginEdge + aContentEdgeToBoxSizing);
|
2013-01-15 16:22:03 +04:00
|
|
|
|
result = std::max(min, std::min(pref, fill));
|
2014-11-27 18:01:11 +03:00
|
|
|
|
NS_ASSERTION(result >= 0, "inline-size less than zero");
|
2007-05-04 03:11:00 +04:00
|
|
|
|
}
|
|
|
|
|
break;
|
2007-11-15 21:10:31 +03:00
|
|
|
|
case NS_STYLE_WIDTH_AVAILABLE:
|
2014-11-27 18:01:11 +03:00
|
|
|
|
result = aContainingBlockISize -
|
2007-05-04 03:11:00 +04:00
|
|
|
|
(aBoxSizingToMarginEdge + aContentEdgeToBoxSizing);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-15 16:22:03 +04:00
|
|
|
|
return std::max(0, result);
|
2012-08-08 19:58:26 +04:00
|
|
|
|
}
|
2007-05-04 03:11:00 +04:00
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
/* static */ nscoord
|
2014-11-27 18:01:11 +03:00
|
|
|
|
nsLayoutUtils::ComputeBSizeDependentValue(
|
|
|
|
|
nscoord aContainingBlockBSize,
|
2006-12-18 16:20:18 +03:00
|
|
|
|
const nsStyleCoord& aCoord)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
{
|
2014-11-27 18:01:11 +03:00
|
|
|
|
// XXXldb Some callers explicitly check aContainingBlockBSize
|
2010-08-25 14:17:55 +04:00
|
|
|
|
// 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'.
|
2014-11-27 18:01:11 +03:00
|
|
|
|
NS_PRECONDITION(NS_AUTOHEIGHT != aContainingBlockBSize ||
|
2010-08-25 14:17:55 +04:00
|
|
|
|
!aCoord.HasPercent(),
|
2014-11-27 18:01:11 +03:00
|
|
|
|
"unexpected containing block block-size");
|
2010-08-25 14:17:55 +04:00
|
|
|
|
|
|
|
|
|
if (aCoord.IsCoordPercentCalcUnit()) {
|
2014-11-27 18:01:11 +03:00
|
|
|
|
return nsRuleNode::ComputeCoordPercentCalc(aCoord, aContainingBlockBSize);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
}
|
2010-08-25 14:17:55 +04:00
|
|
|
|
|
2007-05-11 10:01:31 +04:00
|
|
|
|
NS_ASSERTION(aCoord.GetUnit() == eStyleUnit_None ||
|
2007-05-04 03:11:00 +04:00
|
|
|
|
aCoord.GetUnit() == eStyleUnit_Auto,
|
2014-11-27 18:01:11 +03:00
|
|
|
|
"unexpected block-size value");
|
2006-12-17 17:06:42 +03:00
|
|
|
|
return 0;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-08 09:13:28 +04:00
|
|
|
|
/* static */ void
|
|
|
|
|
nsLayoutUtils::MarkDescendantsDirty(nsIFrame *aSubtreeRoot)
|
|
|
|
|
{
|
|
|
|
|
nsAutoTArray<nsIFrame*, 4> subtrees;
|
|
|
|
|
subtrees.AppendElement(aSubtreeRoot);
|
|
|
|
|
|
|
|
|
|
// dirty descendants, iterating over subtrees that may include
|
|
|
|
|
// additional subtrees associated with placeholders
|
|
|
|
|
do {
|
|
|
|
|
nsIFrame *subtreeRoot = subtrees.ElementAt(subtrees.Length() - 1);
|
|
|
|
|
subtrees.RemoveElementAt(subtrees.Length() - 1);
|
|
|
|
|
|
|
|
|
|
// Mark all descendants dirty (using an nsTArray stack rather than
|
|
|
|
|
// recursion).
|
|
|
|
|
// Note that nsHTMLReflowState::InitResizeFlags has some similar
|
|
|
|
|
// code; see comments there for how and why it differs.
|
|
|
|
|
nsAutoTArray<nsIFrame*, 32> stack;
|
|
|
|
|
stack.AppendElement(subtreeRoot);
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
nsIFrame *f = stack.ElementAt(stack.Length() - 1);
|
|
|
|
|
stack.RemoveElementAt(stack.Length() - 1);
|
|
|
|
|
|
2014-07-24 21:03:26 +04:00
|
|
|
|
f->MarkIntrinsicISizesDirty();
|
2014-04-08 09:13:28 +04:00
|
|
|
|
|
|
|
|
|
if (f->GetType() == nsGkAtoms::placeholderFrame) {
|
|
|
|
|
nsIFrame *oof = nsPlaceholderFrame::GetRealFrameForPlaceholder(f);
|
|
|
|
|
if (!nsLayoutUtils::IsProperAncestorFrame(subtreeRoot, oof)) {
|
|
|
|
|
// We have another distinct subtree we need to mark.
|
|
|
|
|
subtrees.AppendElement(oof);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIFrame::ChildListIterator lists(f);
|
|
|
|
|
for (; !lists.IsDone(); lists.Next()) {
|
|
|
|
|
nsFrameList::Enumerator childFrames(lists.CurrentList());
|
|
|
|
|
for (; !childFrames.AtEnd(); childFrames.Next()) {
|
|
|
|
|
nsIFrame* kid = childFrames.get();
|
|
|
|
|
stack.AppendElement(kid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} while (stack.Length() != 0);
|
|
|
|
|
} while (subtrees.Length() != 0);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-24 18:34:57 +04:00
|
|
|
|
/* static */
|
|
|
|
|
LogicalSize
|
|
|
|
|
nsLayoutUtils::ComputeSizeWithIntrinsicDimensions(WritingMode aWM,
|
2011-04-08 05:04:40 +04:00
|
|
|
|
nsRenderingContext* aRenderingContext, nsIFrame* aFrame,
|
2013-10-01 01:26:04 +04:00
|
|
|
|
const IntrinsicSize& aIntrinsicSize,
|
2014-08-24 18:34:57 +04:00
|
|
|
|
nsSize aIntrinsicRatio,
|
|
|
|
|
const mozilla::LogicalSize& aCBSize,
|
|
|
|
|
const mozilla::LogicalSize& aMargin,
|
|
|
|
|
const mozilla::LogicalSize& aBorder,
|
|
|
|
|
const mozilla::LogicalSize& aPadding)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
{
|
2013-02-17 01:51:02 +04:00
|
|
|
|
const nsStylePosition* stylePos = aFrame->StylePosition();
|
2012-09-06 01:13:37 +04:00
|
|
|
|
|
|
|
|
|
// If we're a flex item, we'll compute our size a bit differently.
|
2014-11-27 18:01:22 +03:00
|
|
|
|
bool isVertical = aWM.IsVertical();
|
2015-05-11 13:37:46 +03:00
|
|
|
|
const nsStyleCoord* inlineStyleCoord = &stylePos->ISize(aWM);
|
|
|
|
|
const nsStyleCoord* blockStyleCoord = &stylePos->BSize(aWM);
|
2012-09-06 01:13:37 +04:00
|
|
|
|
|
|
|
|
|
bool isFlexItem = aFrame->IsFlexItem();
|
2014-08-24 18:34:57 +04:00
|
|
|
|
bool isInlineFlexItem = false;
|
2012-09-06 01:13:37 +04:00
|
|
|
|
|
|
|
|
|
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
|
2014-11-25 22:28:15 +03:00
|
|
|
|
// "flex-basis:auto", in which case they use their main-size property after
|
|
|
|
|
// all.
|
2012-09-06 01:13:37 +04:00
|
|
|
|
uint32_t flexDirection =
|
2013-02-17 01:51:02 +04:00
|
|
|
|
aFrame->GetParent()->StylePosition()->mFlexDirection;
|
2014-08-24 18:34:57 +04:00
|
|
|
|
isInlineFlexItem =
|
2012-09-06 01:13:37 +04:00
|
|
|
|
flexDirection == NS_STYLE_FLEX_DIRECTION_ROW ||
|
|
|
|
|
flexDirection == NS_STYLE_FLEX_DIRECTION_ROW_REVERSE;
|
|
|
|
|
|
2012-10-17 06:04:29 +04:00
|
|
|
|
// NOTE: The logic here should match the similar chunk for determining
|
2014-08-24 18:34:57 +04:00
|
|
|
|
// inlineStyleCoord and blockStyleCoord in nsFrame::ComputeSize().
|
2012-10-17 06:04:29 +04:00
|
|
|
|
const nsStyleCoord* flexBasis = &(stylePos->mFlexBasis);
|
2014-11-25 22:28:15 +03:00
|
|
|
|
if (flexBasis->GetUnit() != eStyleUnit_Auto) {
|
|
|
|
|
if (isInlineFlexItem) {
|
|
|
|
|
inlineStyleCoord = flexBasis;
|
|
|
|
|
} else {
|
|
|
|
|
// One caveat for vertical flex items: We don't support enumerated
|
|
|
|
|
// values (e.g. "max-content") for height properties yet. So, if our
|
|
|
|
|
// computed flex-basis is an enumerated value, we'll just behave as if
|
|
|
|
|
// it were "auto", which means "use the main-size property after all"
|
|
|
|
|
// (which is "height", in this case).
|
|
|
|
|
// NOTE: Once we support intrinsic sizing keywords for "height",
|
|
|
|
|
// we should remove this check.
|
|
|
|
|
if (flexBasis->GetUnit() != eStyleUnit_Enumerated) {
|
|
|
|
|
blockStyleCoord = flexBasis;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-09-06 01:13:37 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
// 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).
|
|
|
|
|
|
2014-08-24 18:34:57 +04:00
|
|
|
|
const bool isAutoISize = inlineStyleCoord->GetUnit() == eStyleUnit_Auto;
|
2014-11-27 18:01:22 +03:00
|
|
|
|
const bool isAutoBSize = IsAutoBSize(*blockStyleCoord, aCBSize.BSize(aWM));
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
2014-08-24 18:34:57 +04:00
|
|
|
|
LogicalSize boxSizingAdjust(aWM);
|
2015-05-29 22:16:53 +03:00
|
|
|
|
switch (stylePos->mBoxSizing) {
|
|
|
|
|
case NS_STYLE_BOX_SIZING_BORDER:
|
|
|
|
|
boxSizingAdjust += aBorder;
|
|
|
|
|
// fall through
|
|
|
|
|
case NS_STYLE_BOX_SIZING_PADDING:
|
|
|
|
|
boxSizingAdjust += aPadding;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
}
|
2014-08-24 18:34:57 +04:00
|
|
|
|
nscoord boxSizingToMarginEdgeISize =
|
|
|
|
|
aMargin.ISize(aWM) + aBorder.ISize(aWM) + aPadding.ISize(aWM) -
|
|
|
|
|
boxSizingAdjust.ISize(aWM);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
2014-08-24 18:34:57 +04:00
|
|
|
|
nscoord iSize, minISize, maxISize, bSize, minBSize, maxBSize;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
2014-08-24 18:34:57 +04:00
|
|
|
|
if (!isAutoISize) {
|
2014-11-27 18:01:22 +03:00
|
|
|
|
iSize = nsLayoutUtils::ComputeISizeValue(aRenderingContext,
|
2014-08-24 18:34:57 +04:00
|
|
|
|
aFrame, aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM),
|
|
|
|
|
boxSizingToMarginEdgeISize, *inlineStyleCoord);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-11 13:37:46 +03:00
|
|
|
|
const nsStyleCoord& maxISizeCoord = stylePos->MaxISize(aWM);
|
2014-11-27 18:01:22 +03:00
|
|
|
|
|
|
|
|
|
if (maxISizeCoord.GetUnit() != eStyleUnit_None &&
|
2014-08-24 18:34:57 +04:00
|
|
|
|
!(isFlexItem && isInlineFlexItem)) {
|
2014-11-27 18:01:22 +03:00
|
|
|
|
maxISize = nsLayoutUtils::ComputeISizeValue(aRenderingContext,
|
2014-08-24 18:34:57 +04:00
|
|
|
|
aFrame, aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM),
|
2014-11-27 18:01:22 +03:00
|
|
|
|
boxSizingToMarginEdgeISize, maxISizeCoord);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
} else {
|
2014-08-24 18:34:57 +04:00
|
|
|
|
maxISize = nscoord_MAX;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-22 19:24:34 +04: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.)
|
2014-11-27 18:01:22 +03:00
|
|
|
|
|
2015-05-11 13:37:46 +03:00
|
|
|
|
const nsStyleCoord& minISizeCoord = stylePos->MinISize(aWM);
|
2014-11-27 18:01:22 +03:00
|
|
|
|
|
|
|
|
|
if (minISizeCoord.GetUnit() != eStyleUnit_Auto &&
|
2014-08-24 18:34:57 +04:00
|
|
|
|
!(isFlexItem && isInlineFlexItem)) {
|
2014-11-27 18:01:22 +03:00
|
|
|
|
minISize = nsLayoutUtils::ComputeISizeValue(aRenderingContext,
|
2014-08-24 18:34:57 +04:00
|
|
|
|
aFrame, aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM),
|
2014-11-27 18:01:22 +03:00
|
|
|
|
boxSizingToMarginEdgeISize, minISizeCoord);
|
2012-09-05 03:26:10 +04:00
|
|
|
|
} else {
|
2014-07-22 19:24:34 +04:00
|
|
|
|
// 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.
|
2014-08-24 18:34:57 +04:00
|
|
|
|
minISize = 0;
|
2012-09-05 03:26:10 +04:00
|
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
2014-08-24 18:34:57 +04:00
|
|
|
|
if (!isAutoBSize) {
|
2014-11-27 18:01:22 +03:00
|
|
|
|
bSize = nsLayoutUtils::ComputeBSizeValue(aCBSize.BSize(aWM),
|
2014-08-24 18:34:57 +04:00
|
|
|
|
boxSizingAdjust.BSize(aWM),
|
|
|
|
|
*blockStyleCoord);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-11 13:37:46 +03:00
|
|
|
|
const nsStyleCoord& maxBSizeCoord = stylePos->MaxBSize(aWM);
|
2014-11-27 18:01:22 +03:00
|
|
|
|
|
|
|
|
|
if (!IsAutoBSize(maxBSizeCoord, aCBSize.BSize(aWM)) &&
|
2014-08-24 18:34:57 +04:00
|
|
|
|
!(isFlexItem && !isInlineFlexItem)) {
|
2014-11-27 18:01:22 +03:00
|
|
|
|
maxBSize = nsLayoutUtils::ComputeBSizeValue(aCBSize.BSize(aWM),
|
|
|
|
|
boxSizingAdjust.BSize(aWM), maxBSizeCoord);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
} else {
|
2014-08-24 18:34:57 +04:00
|
|
|
|
maxBSize = nscoord_MAX;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-11 13:37:46 +03:00
|
|
|
|
const nsStyleCoord& minBSizeCoord = stylePos->MinBSize(aWM);
|
2014-11-27 18:01:22 +03:00
|
|
|
|
|
|
|
|
|
if (!IsAutoBSize(minBSizeCoord, aCBSize.BSize(aWM)) &&
|
2014-08-24 18:34:57 +04:00
|
|
|
|
!(isFlexItem && !isInlineFlexItem)) {
|
2014-11-27 18:01:22 +03:00
|
|
|
|
minBSize = nsLayoutUtils::ComputeBSizeValue(aCBSize.BSize(aWM),
|
|
|
|
|
boxSizingAdjust.BSize(aWM), minBSizeCoord);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
} else {
|
2014-08-24 18:34:57 +04:00
|
|
|
|
minBSize = 0;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-24 18:34:57 +04:00
|
|
|
|
// Resolve percentage intrinsic iSize/bSize as necessary:
|
2007-11-18 15:09:03 +03:00
|
|
|
|
|
2014-08-24 18:34:57 +04:00
|
|
|
|
NS_ASSERTION(aCBSize.ISize(aWM) != NS_UNCONSTRAINEDSIZE,
|
|
|
|
|
"Our containing block must not have unconstrained inline-size!");
|
|
|
|
|
|
2014-11-27 18:01:22 +03:00
|
|
|
|
const nsStyleCoord& isizeCoord =
|
|
|
|
|
isVertical ? aIntrinsicSize.height : aIntrinsicSize.width;
|
|
|
|
|
const nsStyleCoord& bsizeCoord =
|
|
|
|
|
isVertical ? aIntrinsicSize.width : aIntrinsicSize.height;
|
2007-11-18 15:09:03 +03:00
|
|
|
|
|
2014-07-24 21:03:26 +04:00
|
|
|
|
bool hasIntrinsicISize, hasIntrinsicBSize;
|
|
|
|
|
nscoord intrinsicISize, intrinsicBSize;
|
2007-11-18 15:09:03 +03:00
|
|
|
|
|
2014-08-24 18:34:57 +04:00
|
|
|
|
if (isizeCoord.GetUnit() == eStyleUnit_Coord) {
|
2014-07-24 21:03:26 +04:00
|
|
|
|
hasIntrinsicISize = true;
|
2014-08-24 18:34:57 +04:00
|
|
|
|
intrinsicISize = isizeCoord.GetCoordValue();
|
2014-07-24 21:03:26 +04:00
|
|
|
|
if (intrinsicISize < 0)
|
|
|
|
|
intrinsicISize = 0;
|
2007-11-18 15:09:03 +03:00
|
|
|
|
} else {
|
2014-08-24 18:34:57 +04:00
|
|
|
|
NS_ASSERTION(isizeCoord.GetUnit() == eStyleUnit_None,
|
2011-06-13 05:52:32 +04:00
|
|
|
|
"unexpected unit");
|
2014-07-24 21:03:26 +04:00
|
|
|
|
hasIntrinsicISize = false;
|
|
|
|
|
intrinsicISize = 0;
|
2007-11-18 15:09:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-24 18:34:57 +04:00
|
|
|
|
if (bsizeCoord.GetUnit() == eStyleUnit_Coord) {
|
2014-07-24 21:03:26 +04:00
|
|
|
|
hasIntrinsicBSize = true;
|
2014-08-24 18:34:57 +04:00
|
|
|
|
intrinsicBSize = bsizeCoord.GetCoordValue();
|
2014-07-24 21:03:26 +04:00
|
|
|
|
if (intrinsicBSize < 0)
|
|
|
|
|
intrinsicBSize = 0;
|
2007-11-18 15:09:03 +03:00
|
|
|
|
} else {
|
2014-08-24 18:34:57 +04:00
|
|
|
|
NS_ASSERTION(bsizeCoord.GetUnit() == eStyleUnit_None,
|
2011-06-13 05:52:32 +04:00
|
|
|
|
"unexpected unit");
|
2014-07-24 21:03:26 +04:00
|
|
|
|
hasIntrinsicBSize = false;
|
|
|
|
|
intrinsicBSize = 0;
|
2007-11-18 15:09:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NS_ASSERTION(aIntrinsicRatio.width >= 0 && aIntrinsicRatio.height >= 0,
|
|
|
|
|
"Intrinsic ratio has a negative component!");
|
2014-08-24 18:34:57 +04:00
|
|
|
|
LogicalSize logicalRatio(aWM, aIntrinsicRatio);
|
2007-11-18 15:09:03 +03:00
|
|
|
|
|
2014-08-24 18:34:57 +04:00
|
|
|
|
// Now calculate the used values for iSize and bSize:
|
2007-11-18 15:09:03 +03:00
|
|
|
|
|
2014-08-24 18:34:57 +04:00
|
|
|
|
if (isAutoISize) {
|
|
|
|
|
if (isAutoBSize) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
2014-08-24 18:34:57 +04:00
|
|
|
|
// 'auto' iSize, 'auto' bSize
|
2007-11-18 15:09:03 +03:00
|
|
|
|
|
|
|
|
|
// Get tentative values - CSS 2.1 sections 10.3.2 and 10.6.2:
|
|
|
|
|
|
2014-08-24 18:34:57 +04:00
|
|
|
|
nscoord tentISize, tentBSize;
|
2007-11-18 15:09:03 +03:00
|
|
|
|
|
2014-07-24 21:03:26 +04:00
|
|
|
|
if (hasIntrinsicISize) {
|
2014-08-24 18:34:57 +04:00
|
|
|
|
tentISize = intrinsicISize;
|
|
|
|
|
} else if (hasIntrinsicBSize && logicalRatio.BSize(aWM) > 0) {
|
2014-08-29 09:14:00 +04:00
|
|
|
|
tentISize = NSCoordMulDiv(intrinsicBSize, logicalRatio.ISize(aWM), logicalRatio.BSize(aWM));
|
2014-08-24 18:34:57 +04:00
|
|
|
|
} else if (logicalRatio.ISize(aWM) > 0) {
|
|
|
|
|
tentISize = aCBSize.ISize(aWM) - boxSizingToMarginEdgeISize; // XXX scrollbar?
|
|
|
|
|
if (tentISize < 0) tentISize = 0;
|
2007-11-18 15:09:03 +03:00
|
|
|
|
} else {
|
2014-08-24 18:34:57 +04:00
|
|
|
|
tentISize = nsPresContext::CSSPixelsToAppUnits(300);
|
2007-11-18 15:09:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-24 21:03:26 +04:00
|
|
|
|
if (hasIntrinsicBSize) {
|
2014-08-24 18:34:57 +04:00
|
|
|
|
tentBSize = intrinsicBSize;
|
|
|
|
|
} else if (logicalRatio.ISize(aWM) > 0) {
|
2014-08-29 09:14:00 +04:00
|
|
|
|
tentBSize = NSCoordMulDiv(tentISize, logicalRatio.BSize(aWM), logicalRatio.ISize(aWM));
|
2007-11-18 15:09:03 +03:00
|
|
|
|
} else {
|
2014-08-24 18:34:57 +04:00
|
|
|
|
tentBSize = nsPresContext::CSSPixelsToAppUnits(150);
|
2007-11-18 15:09:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-19 03:49:52 +03:00
|
|
|
|
if (aIntrinsicRatio != nsSize(0, 0)) {
|
|
|
|
|
nsSize autoSize =
|
|
|
|
|
ComputeAutoSizeWithIntrinsicDimensions(minISize, minBSize,
|
|
|
|
|
maxISize, maxBSize,
|
|
|
|
|
tentISize, tentBSize);
|
|
|
|
|
// The nsSize that ComputeAutoSizeWithIntrinsicDimensions returns will
|
|
|
|
|
// actually contain logical values if the parameters passed to it were
|
|
|
|
|
// logical coordinates, so we do NOT perform a physical-to-logical
|
|
|
|
|
// conversion here, but just assign the fields directly to our result.
|
|
|
|
|
iSize = autoSize.width;
|
|
|
|
|
bSize = autoSize.height;
|
|
|
|
|
} else {
|
|
|
|
|
// No intrinsic ratio, so just clamp the dimensions
|
|
|
|
|
// independently without calling
|
|
|
|
|
// ComputeAutoSizeWithIntrinsicDimensions, which deals with
|
|
|
|
|
// propagating these changes to the other dimension (and would
|
|
|
|
|
// be incorrect when there is no intrinsic ratio).
|
|
|
|
|
iSize = NS_CSS_MINMAX(tentISize, minISize, maxISize);
|
|
|
|
|
bSize = NS_CSS_MINMAX(tentBSize, minBSize, maxBSize);
|
|
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
} else {
|
|
|
|
|
|
2014-08-24 18:34:57 +04:00
|
|
|
|
// 'auto' iSize, non-'auto' bSize
|
|
|
|
|
bSize = NS_CSS_MINMAX(bSize, minBSize, maxBSize);
|
|
|
|
|
if (logicalRatio.BSize(aWM) > 0) {
|
2014-08-29 09:14:00 +04:00
|
|
|
|
iSize = NSCoordMulDiv(bSize, logicalRatio.ISize(aWM), logicalRatio.BSize(aWM));
|
2014-07-24 21:03:26 +04:00
|
|
|
|
} else if (hasIntrinsicISize) {
|
2014-08-24 18:34:57 +04:00
|
|
|
|
iSize = intrinsicISize;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
} else {
|
2014-08-24 18:34:57 +04:00
|
|
|
|
iSize = nsPresContext::CSSPixelsToAppUnits(300);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
}
|
2014-08-24 18:34:57 +04:00
|
|
|
|
iSize = NS_CSS_MINMAX(iSize, minISize, maxISize);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2014-08-24 18:34:57 +04:00
|
|
|
|
if (isAutoBSize) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
2014-08-24 18:34:57 +04:00
|
|
|
|
// non-'auto' iSize, 'auto' bSize
|
|
|
|
|
iSize = NS_CSS_MINMAX(iSize, minISize, maxISize);
|
|
|
|
|
if (logicalRatio.ISize(aWM) > 0) {
|
2014-08-29 09:14:00 +04:00
|
|
|
|
bSize = NSCoordMulDiv(iSize, logicalRatio.BSize(aWM), logicalRatio.ISize(aWM));
|
2014-07-24 21:03:26 +04:00
|
|
|
|
} else if (hasIntrinsicBSize) {
|
2014-08-24 18:34:57 +04:00
|
|
|
|
bSize = intrinsicBSize;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
} else {
|
2014-08-24 18:34:57 +04:00
|
|
|
|
bSize = nsPresContext::CSSPixelsToAppUnits(150);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
}
|
2014-08-24 18:34:57 +04:00
|
|
|
|
bSize = NS_CSS_MINMAX(bSize, minBSize, maxBSize);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
2014-08-24 18:34:57 +04:00
|
|
|
|
// non-'auto' iSize, non-'auto' bSize
|
|
|
|
|
iSize = NS_CSS_MINMAX(iSize, minISize, maxISize);
|
|
|
|
|
bSize = NS_CSS_MINMAX(bSize, minBSize, maxBSize);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-24 18:34:57 +04:00
|
|
|
|
return LogicalSize(aWM, iSize, bSize);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-05 23:24:24 +04: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) {
|
2014-08-29 09:14:00 +04:00
|
|
|
|
heightAtMaxWidth = NSCoordMulDiv(maxWidth, tentHeight, tentWidth);
|
2011-08-05 23:24:24 +04:00
|
|
|
|
if (heightAtMaxWidth < minHeight)
|
|
|
|
|
heightAtMaxWidth = minHeight;
|
2014-08-29 09:14:00 +04:00
|
|
|
|
heightAtMinWidth = NSCoordMulDiv(minWidth, tentHeight, tentWidth);
|
2011-08-05 23:24:24 +04:00
|
|
|
|
if (heightAtMinWidth > maxHeight)
|
|
|
|
|
heightAtMinWidth = maxHeight;
|
|
|
|
|
} else {
|
2011-08-18 04:54:59 +04:00
|
|
|
|
heightAtMaxWidth = heightAtMinWidth = NS_CSS_MINMAX(tentHeight, minHeight, maxHeight);
|
2011-08-05 23:24:24 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tentHeight > 0) {
|
2014-08-29 09:14:00 +04:00
|
|
|
|
widthAtMaxHeight = NSCoordMulDiv(maxHeight, tentWidth, tentHeight);
|
2011-08-05 23:24:24 +04:00
|
|
|
|
if (widthAtMaxHeight < minWidth)
|
|
|
|
|
widthAtMaxHeight = minWidth;
|
2014-08-29 09:14:00 +04:00
|
|
|
|
widthAtMinHeight = NSCoordMulDiv(minHeight, tentWidth, tentHeight);
|
2011-08-05 23:24:24 +04:00
|
|
|
|
if (widthAtMinHeight > maxWidth)
|
|
|
|
|
widthAtMinHeight = maxWidth;
|
|
|
|
|
} else {
|
2011-08-18 04:54:59 +04:00
|
|
|
|
widthAtMaxHeight = widthAtMinHeight = NS_CSS_MINMAX(tentWidth, minWidth, maxWidth);
|
2011-08-05 23:24:24 +04: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 19:56:38 +04:00
|
|
|
|
if (int64_t(maxWidth) * int64_t(tentHeight) <=
|
|
|
|
|
int64_t(maxHeight) * int64_t(tentWidth)) {
|
2011-08-05 23:24:24 +04: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 19:56:38 +04:00
|
|
|
|
if (int64_t(minWidth) * int64_t(tentHeight) <=
|
|
|
|
|
int64_t(minHeight) * int64_t(tentWidth)) {
|
2011-08-05 23:24:24 +04: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);
|
|
|
|
|
}
|
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
/* static */ nscoord
|
2014-07-24 21:03:25 +04:00
|
|
|
|
nsLayoutUtils::MinISizeFromInline(nsIFrame* aFrame,
|
2011-04-08 05:04:40 +04:00
|
|
|
|
nsRenderingContext* aRenderingContext)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
{
|
2013-10-01 01:26:04 +04:00
|
|
|
|
NS_ASSERTION(!aFrame->IsContainerForFontSizeInflation(),
|
2012-01-25 05:21:29 +04:00
|
|
|
|
"should not be container for font size inflation");
|
|
|
|
|
|
2014-07-24 21:03:25 +04:00
|
|
|
|
nsIFrame::InlineMinISizeData data;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
DISPLAY_MIN_WIDTH(aFrame, data.prevLines);
|
2014-07-24 21:03:25 +04:00
|
|
|
|
aFrame->AddInlineMinISize(aRenderingContext, &data);
|
2007-06-22 02:32:47 +04:00
|
|
|
|
data.ForceBreak(aRenderingContext);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
return data.prevLines;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* static */ nscoord
|
2014-07-24 21:03:25 +04:00
|
|
|
|
nsLayoutUtils::PrefISizeFromInline(nsIFrame* aFrame,
|
2011-04-08 05:04:40 +04:00
|
|
|
|
nsRenderingContext* aRenderingContext)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
{
|
2013-10-01 01:26:04 +04:00
|
|
|
|
NS_ASSERTION(!aFrame->IsContainerForFontSizeInflation(),
|
2012-01-25 05:21:29 +04:00
|
|
|
|
"should not be container for font size inflation");
|
|
|
|
|
|
2014-07-24 21:03:25 +04:00
|
|
|
|
nsIFrame::InlinePrefISizeData data;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
DISPLAY_PREF_WIDTH(aFrame, data.prevLines);
|
2014-07-24 21:03:25 +04:00
|
|
|
|
aFrame->AddInlinePrefISize(aRenderingContext, &data);
|
2007-06-22 02:32:47 +04:00
|
|
|
|
data.ForceBreak(aRenderingContext);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
return data.prevLines;
|
|
|
|
|
}
|
2007-01-23 05:58:55 +03:00
|
|
|
|
|
2011-06-22 22:11:48 +04:00
|
|
|
|
static nscolor
|
|
|
|
|
DarkenColor(nscolor aColor)
|
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint16_t hue, sat, value;
|
|
|
|
|
uint8_t alpha;
|
2011-06-22 22:11:48 +04: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 19:14:36 +04:00
|
|
|
|
// Check whether we should darken text/decoration colors. We need to do this if
|
2011-06-22 22:11:48 +04: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-29 10:19:26 +04:00
|
|
|
|
static bool
|
2011-06-22 22:11:48 +04:00
|
|
|
|
ShouldDarkenColors(nsPresContext* aPresContext)
|
|
|
|
|
{
|
|
|
|
|
return !aPresContext->GetBackgroundColorDraw() &&
|
2011-08-09 19:14:36 +04:00
|
|
|
|
!aPresContext->GetBackgroundImageDraw();
|
2011-06-22 22:11:48 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nscolor
|
2011-08-09 19:14:36 +04:00
|
|
|
|
nsLayoutUtils::GetColor(nsIFrame* aFrame, nsCSSProperty aProperty)
|
2011-06-22 22:11:48 +04:00
|
|
|
|
{
|
2011-08-09 19:14:36 +04:00
|
|
|
|
nscolor color = aFrame->GetVisitedDependentColor(aProperty);
|
2011-06-22 22:11:48 +04:00
|
|
|
|
if (ShouldDarkenColors(aFrame->PresContext())) {
|
|
|
|
|
color = DarkenColor(color);
|
|
|
|
|
}
|
|
|
|
|
return color;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-04 09:47:59 +04: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 18:59:28 +04:00
|
|
|
|
if (!aContext->UserToDevicePixelSnapped(putativeRect, true))
|
2011-07-04 09:47:59 +04:00
|
|
|
|
return baseline;
|
|
|
|
|
return aContext->DeviceToUser(putativeRect.TopLeft()).y * appUnitsPerDevUnit;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-11 13:59:06 +03:00
|
|
|
|
gfxFloat
|
|
|
|
|
nsLayoutUtils::GetSnappedBaselineX(nsIFrame* aFrame, gfxContext* aContext,
|
|
|
|
|
nscoord aX, nscoord aAscent)
|
|
|
|
|
{
|
|
|
|
|
gfxFloat appUnitsPerDevUnit = aFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
|
gfxFloat baseline = gfxFloat(aX) + aAscent;
|
|
|
|
|
gfxRect putativeRect(baseline / appUnitsPerDevUnit, 0, 1, 1);
|
|
|
|
|
if (!aContext->UserToDevicePixelSnapped(putativeRect, true)) {
|
|
|
|
|
return baseline;
|
|
|
|
|
}
|
|
|
|
|
return aContext->DeviceToUser(putativeRect.TopLeft()).x * appUnitsPerDevUnit;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-24 19:28:14 +04:00
|
|
|
|
// Hard limit substring lengths to 8000 characters ... this lets us statically
|
|
|
|
|
// size the cluster buffer array in FindSafeLength
|
|
|
|
|
#define MAX_GFX_TEXT_BUF_SIZE 8000
|
|
|
|
|
|
|
|
|
|
static int32_t FindSafeLength(const char16_t *aString, uint32_t aLength,
|
|
|
|
|
uint32_t aMaxChunkLength)
|
|
|
|
|
{
|
|
|
|
|
if (aLength <= aMaxChunkLength)
|
|
|
|
|
return aLength;
|
|
|
|
|
|
|
|
|
|
int32_t len = aMaxChunkLength;
|
|
|
|
|
|
|
|
|
|
// Ensure that we don't break inside a surrogate pair
|
|
|
|
|
while (len > 0 && NS_IS_LOW_SURROGATE(aString[len])) {
|
|
|
|
|
len--;
|
|
|
|
|
}
|
|
|
|
|
if (len == 0) {
|
|
|
|
|
// We don't want our caller to go into an infinite loop, so don't
|
|
|
|
|
// return zero. It's hard to imagine how we could actually get here
|
|
|
|
|
// unless there are languages that allow clusters of arbitrary size.
|
|
|
|
|
// If there are and someone feeds us a 500+ character cluster, too
|
|
|
|
|
// bad.
|
|
|
|
|
return aMaxChunkLength;
|
|
|
|
|
}
|
|
|
|
|
return len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int32_t GetMaxChunkLength(nsFontMetrics& aFontMetrics)
|
|
|
|
|
{
|
|
|
|
|
return std::min(aFontMetrics.GetMaxStringLength(), MAX_GFX_TEXT_BUF_SIZE);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-24 19:28:13 +04:00
|
|
|
|
nscoord
|
|
|
|
|
nsLayoutUtils::AppUnitWidthOfString(const char16_t *aString,
|
|
|
|
|
uint32_t aLength,
|
2014-10-24 19:28:14 +04:00
|
|
|
|
nsFontMetrics& aFontMetrics,
|
2014-10-24 19:28:13 +04:00
|
|
|
|
nsRenderingContext& aContext)
|
|
|
|
|
{
|
2014-10-24 19:28:14 +04:00
|
|
|
|
uint32_t maxChunkLength = GetMaxChunkLength(aFontMetrics);
|
2014-10-24 19:28:13 +04:00
|
|
|
|
nscoord width = 0;
|
|
|
|
|
while (aLength > 0) {
|
2014-10-24 19:28:14 +04:00
|
|
|
|
int32_t len = FindSafeLength(aString, aLength, maxChunkLength);
|
2014-10-24 19:28:14 +04:00
|
|
|
|
width += aFontMetrics.GetWidth(aString, len, &aContext);
|
2014-10-24 19:28:13 +04:00
|
|
|
|
aLength -= len;
|
|
|
|
|
aString += len;
|
|
|
|
|
}
|
|
|
|
|
return width;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-26 20:57:49 +03:00
|
|
|
|
nscoord
|
|
|
|
|
nsLayoutUtils::AppUnitWidthOfStringBidi(const char16_t* aString,
|
|
|
|
|
uint32_t aLength,
|
|
|
|
|
const nsIFrame* aFrame,
|
|
|
|
|
nsFontMetrics& aFontMetrics,
|
|
|
|
|
nsRenderingContext& aContext)
|
|
|
|
|
{
|
|
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
|
|
|
|
if (presContext->BidiEnabled()) {
|
|
|
|
|
nsBidiLevel level =
|
|
|
|
|
nsBidiPresUtils::BidiLevelFromStyle(aFrame->StyleContext());
|
|
|
|
|
return nsBidiPresUtils::MeasureTextWidth(aString, aLength, level,
|
|
|
|
|
presContext, aContext,
|
|
|
|
|
aFontMetrics);
|
|
|
|
|
}
|
|
|
|
|
aFontMetrics.SetTextRunRTL(false);
|
2015-01-06 23:56:03 +03:00
|
|
|
|
aFontMetrics.SetVertical(aFrame->GetWritingMode().IsVertical());
|
|
|
|
|
aFontMetrics.SetTextOrientation(aFrame->StyleVisibility()->mTextOrientation);
|
2014-10-26 20:57:49 +03:00
|
|
|
|
return nsLayoutUtils::AppUnitWidthOfString(aString, aLength, aFontMetrics,
|
|
|
|
|
aContext);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-10 14:07:58 +03:00
|
|
|
|
bool
|
|
|
|
|
nsLayoutUtils::StringWidthIsGreaterThan(const nsString& aString,
|
|
|
|
|
nsFontMetrics& aFontMetrics,
|
|
|
|
|
nsRenderingContext& aContext,
|
|
|
|
|
nscoord aWidth)
|
|
|
|
|
{
|
|
|
|
|
const char16_t *string = aString.get();
|
|
|
|
|
uint32_t length = aString.Length();
|
|
|
|
|
uint32_t maxChunkLength = GetMaxChunkLength(aFontMetrics);
|
|
|
|
|
nscoord width = 0;
|
|
|
|
|
while (length > 0) {
|
|
|
|
|
int32_t len = FindSafeLength(string, length, maxChunkLength);
|
|
|
|
|
width += aFontMetrics.GetWidth(string, len, &aContext);
|
|
|
|
|
if (width > aWidth) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
length -= len;
|
|
|
|
|
string += len;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-24 19:28:14 +04:00
|
|
|
|
nsBoundingMetrics
|
|
|
|
|
nsLayoutUtils::AppUnitBoundsOfString(const char16_t* aString,
|
|
|
|
|
uint32_t aLength,
|
2014-10-24 19:28:14 +04:00
|
|
|
|
nsFontMetrics& aFontMetrics,
|
2014-10-24 19:28:14 +04:00
|
|
|
|
nsRenderingContext& aContext)
|
|
|
|
|
{
|
2014-10-24 19:28:14 +04:00
|
|
|
|
uint32_t maxChunkLength = GetMaxChunkLength(aFontMetrics);
|
2014-10-24 19:28:14 +04:00
|
|
|
|
int32_t len = FindSafeLength(aString, aLength, maxChunkLength);
|
|
|
|
|
// Assign directly in the first iteration. This ensures that
|
|
|
|
|
// negative ascent/descent can be returned and the left bearing
|
|
|
|
|
// is properly initialized.
|
|
|
|
|
nsBoundingMetrics totalMetrics =
|
2014-10-24 19:28:14 +04:00
|
|
|
|
aFontMetrics.GetBoundingMetrics(aString, len, &aContext);
|
2014-10-24 19:28:14 +04:00
|
|
|
|
aLength -= len;
|
|
|
|
|
aString += len;
|
|
|
|
|
|
|
|
|
|
while (aLength > 0) {
|
|
|
|
|
len = FindSafeLength(aString, aLength, maxChunkLength);
|
|
|
|
|
nsBoundingMetrics metrics =
|
2014-10-24 19:28:14 +04:00
|
|
|
|
aFontMetrics.GetBoundingMetrics(aString, len, &aContext);
|
2014-10-24 19:28:14 +04:00
|
|
|
|
totalMetrics += metrics;
|
|
|
|
|
aLength -= len;
|
|
|
|
|
aString += len;
|
|
|
|
|
}
|
|
|
|
|
return totalMetrics;
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-23 05:58:55 +03:00
|
|
|
|
void
|
2013-11-18 19:24:16 +04:00
|
|
|
|
nsLayoutUtils::DrawString(const nsIFrame* aFrame,
|
2014-10-24 19:28:14 +04:00
|
|
|
|
nsFontMetrics& aFontMetrics,
|
2013-11-18 19:24:16 +04:00
|
|
|
|
nsRenderingContext* aContext,
|
2014-01-04 19:02:17 +04:00
|
|
|
|
const char16_t* aString,
|
2013-11-18 19:24:16 +04:00
|
|
|
|
int32_t aLength,
|
|
|
|
|
nsPoint aPoint,
|
|
|
|
|
nsStyleContext* aStyleContext)
|
2007-01-23 05:58:55 +03:00
|
|
|
|
{
|
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
2015-01-06 23:56:03 +03:00
|
|
|
|
|
|
|
|
|
// If caller didn't pass a style context, use the frame's.
|
|
|
|
|
if (!aStyleContext) {
|
|
|
|
|
aStyleContext = aFrame->StyleContext();
|
|
|
|
|
}
|
|
|
|
|
aFontMetrics.SetVertical(WritingMode(aStyleContext).IsVertical());
|
|
|
|
|
aFontMetrics.SetTextOrientation(
|
|
|
|
|
aStyleContext->StyleVisibility()->mTextOrientation);
|
|
|
|
|
|
2007-03-31 01:11:41 +04:00
|
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
2007-01-25 22:54:38 +03:00
|
|
|
|
if (presContext->BidiEnabled()) {
|
2013-11-18 19:24:16 +04:00
|
|
|
|
nsBidiLevel level =
|
2015-01-06 23:56:03 +03:00
|
|
|
|
nsBidiPresUtils::BidiLevelFromStyle(aStyleContext);
|
2013-11-18 19:24:16 +04:00
|
|
|
|
rv = nsBidiPresUtils::RenderText(aString, aLength, level,
|
2011-04-13 13:23:49 +04:00
|
|
|
|
presContext, *aContext, *aContext,
|
2014-10-24 19:28:14 +04:00
|
|
|
|
aFontMetrics,
|
2011-04-13 13:23:49 +04:00
|
|
|
|
aPoint.x, aPoint.y);
|
2007-01-23 05:58:55 +03:00
|
|
|
|
}
|
|
|
|
|
if (NS_FAILED(rv))
|
2010-04-27 20:15:01 +04:00
|
|
|
|
{
|
2014-10-24 19:28:14 +04:00
|
|
|
|
aFontMetrics.SetTextRunRTL(false);
|
|
|
|
|
DrawUniDirString(aString, aLength, aPoint, aFontMetrics, *aContext);
|
2007-01-23 05:58:55 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-24 14:00:23 +04:00
|
|
|
|
void
|
|
|
|
|
nsLayoutUtils::DrawUniDirString(const char16_t* aString,
|
|
|
|
|
uint32_t aLength,
|
|
|
|
|
nsPoint aPoint,
|
2014-10-24 19:28:14 +04:00
|
|
|
|
nsFontMetrics& aFontMetrics,
|
2014-10-24 14:00:23 +04:00
|
|
|
|
nsRenderingContext& aContext)
|
|
|
|
|
{
|
2014-10-24 14:00:23 +04:00
|
|
|
|
nscoord x = aPoint.x;
|
|
|
|
|
nscoord y = aPoint.y;
|
|
|
|
|
|
2014-10-24 19:28:14 +04:00
|
|
|
|
uint32_t maxChunkLength = GetMaxChunkLength(aFontMetrics);
|
2014-10-24 14:00:23 +04:00
|
|
|
|
if (aLength <= maxChunkLength) {
|
2014-10-24 19:28:14 +04:00
|
|
|
|
aFontMetrics.DrawString(aString, aLength, x, y, &aContext, &aContext);
|
2014-10-24 14:00:23 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-24 19:28:14 +04:00
|
|
|
|
bool isRTL = aFontMetrics.GetTextRunRTL();
|
2014-10-24 14:00:23 +04:00
|
|
|
|
|
|
|
|
|
// If we're drawing right to left, we must start at the end.
|
|
|
|
|
if (isRTL) {
|
2014-10-24 19:28:14 +04:00
|
|
|
|
x += nsLayoutUtils::AppUnitWidthOfString(aString, aLength, aFontMetrics,
|
|
|
|
|
aContext);
|
2014-10-24 14:00:23 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (aLength > 0) {
|
2014-10-24 19:28:14 +04:00
|
|
|
|
int32_t len = FindSafeLength(aString, aLength, maxChunkLength);
|
2014-10-24 19:28:14 +04:00
|
|
|
|
nscoord width = aFontMetrics.GetWidth(aString, len, &aContext);
|
2014-10-24 14:00:23 +04:00
|
|
|
|
if (isRTL) {
|
|
|
|
|
x -= width;
|
|
|
|
|
}
|
2014-10-24 19:28:14 +04:00
|
|
|
|
aFontMetrics.DrawString(aString, len, x, y, &aContext, &aContext);
|
2014-10-24 14:00:23 +04:00
|
|
|
|
if (!isRTL) {
|
|
|
|
|
x += width;
|
|
|
|
|
}
|
|
|
|
|
aLength -= len;
|
|
|
|
|
aString += len;
|
|
|
|
|
}
|
2014-10-24 14:00:23 +04:00
|
|
|
|
}
|
|
|
|
|
|
2011-07-01 10:43:11 +04:00
|
|
|
|
/* static */ void
|
|
|
|
|
nsLayoutUtils::PaintTextShadow(const nsIFrame* aFrame,
|
|
|
|
|
nsRenderingContext* aContext,
|
|
|
|
|
const nsRect& aTextRect,
|
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
|
const nscolor& aForegroundColor,
|
|
|
|
|
TextShadowCallback aCallback,
|
|
|
|
|
void* aCallbackData)
|
|
|
|
|
{
|
2013-02-17 01:51:02 +04:00
|
|
|
|
const nsStyleText* textStyle = aFrame->StyleText();
|
2014-01-13 16:21:42 +04:00
|
|
|
|
if (!textStyle->HasTextShadow())
|
2011-07-01 10:43:11 +04: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 19:56:38 +04:00
|
|
|
|
for (uint32_t i = textStyle->mTextShadow->Length(); i > 0; --i) {
|
2011-07-01 10:43:11 +04:00
|
|
|
|
nsCSSShadowItem* shadowDetails = textStyle->mTextShadow->ShadowAt(i - 1);
|
|
|
|
|
nsPoint shadowOffset(shadowDetails->mXOffset,
|
|
|
|
|
shadowDetails->mYOffset);
|
2013-01-15 16:22:03 +04:00
|
|
|
|
nscoord blurRadius = std::max(shadowDetails->mRadius, 0);
|
2011-07-01 10:43:11 +04:00
|
|
|
|
|
|
|
|
|
nsRect shadowRect(aTextRect);
|
|
|
|
|
shadowRect.MoveBy(shadowOffset);
|
|
|
|
|
|
|
|
|
|
nsPresContext* presCtx = aFrame->PresContext();
|
|
|
|
|
nsContextBoxBlur contextBoxBlur;
|
|
|
|
|
gfxContext* shadowContext = contextBoxBlur.Init(shadowRect, 0, blurRadius,
|
|
|
|
|
presCtx->AppUnitsPerDevPixel(),
|
2012-07-30 18:20:58 +04:00
|
|
|
|
aDestCtx, aDirtyRect, nullptr);
|
2011-07-01 10:43:11 +04: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-07-01 10:48:30 +04:00
|
|
|
|
// to blur.
|
2014-10-31 23:08:49 +03:00
|
|
|
|
nsRenderingContext renderingContext(shadowContext);
|
2011-07-01 10:43:11 +04:00
|
|
|
|
|
|
|
|
|
aDestCtx->Save();
|
|
|
|
|
aDestCtx->NewPath();
|
|
|
|
|
aDestCtx->SetColor(gfxRGBA(shadowColor));
|
|
|
|
|
|
|
|
|
|
// The callback will draw whatever we want to blur as a shadow.
|
2014-10-31 23:08:49 +03:00
|
|
|
|
aCallback(&renderingContext, shadowOffset, shadowColor, aCallbackData);
|
2011-07-01 10:43:11 +04:00
|
|
|
|
|
|
|
|
|
contextBoxBlur.DoPaint();
|
|
|
|
|
aDestCtx->Restore();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-19 02:13:12 +04:00
|
|
|
|
/* static */ nscoord
|
2011-04-08 05:05:49 +04:00
|
|
|
|
nsLayoutUtils::GetCenteredFontBaseline(nsFontMetrics* aFontMetrics,
|
2014-11-13 11:58:06 +03:00
|
|
|
|
nscoord aLineHeight,
|
|
|
|
|
bool aIsInverted)
|
2009-05-19 02:13:12 +04:00
|
|
|
|
{
|
2014-11-13 11:58:06 +03:00
|
|
|
|
nscoord fontAscent = aIsInverted ? aFontMetrics->MaxDescent()
|
|
|
|
|
: aFontMetrics->MaxAscent();
|
2011-04-08 08:18:43 +04:00
|
|
|
|
nscoord fontHeight = aFontMetrics->MaxHeight();
|
2009-05-19 02:13:12 +04:00
|
|
|
|
|
|
|
|
|
nscoord leading = aLineHeight - fontHeight;
|
|
|
|
|
return fontAscent + leading/2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
|
/* static */ bool
|
2014-06-17 16:19:38 +04:00
|
|
|
|
nsLayoutUtils::GetFirstLineBaseline(WritingMode aWritingMode,
|
|
|
|
|
const nsIFrame* aFrame, nscoord* aResult)
|
2009-04-09 00:52:36 +04:00
|
|
|
|
{
|
|
|
|
|
LinePosition position;
|
2014-06-17 16:19:38 +04:00
|
|
|
|
if (!GetFirstLinePosition(aWritingMode, aFrame, &position))
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2009-04-09 00:52:36 +04:00
|
|
|
|
*aResult = position.mBaseline;
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true;
|
2009-04-09 00:52:36 +04:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
|
/* static */ bool
|
2014-06-17 16:19:38 +04:00
|
|
|
|
nsLayoutUtils::GetFirstLinePosition(WritingMode aWM,
|
|
|
|
|
const nsIFrame* aFrame,
|
2009-04-09 00:52:36 +04:00
|
|
|
|
LinePosition* aResult)
|
2007-01-23 07:06:56 +03:00
|
|
|
|
{
|
2008-07-14 02:10:23 +04:00
|
|
|
|
const nsBlockFrame* block = nsLayoutUtils::GetAsBlock(const_cast<nsIFrame*>(aFrame));
|
|
|
|
|
if (!block) {
|
2007-01-23 07:06:56 +03: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) {
|
2014-06-17 16:19:38 +04:00
|
|
|
|
aResult->mBStart = 0;
|
|
|
|
|
aResult->mBaseline = aFrame->GetLogicalBaseline(aWM);
|
2009-04-09 00:52:36 +04:00
|
|
|
|
// This is what we want for the list bullet caller; not sure if
|
|
|
|
|
// other future callers will want the same.
|
2014-06-17 16:19:38 +04:00
|
|
|
|
aResult->mBEnd = aFrame->BSize(aWM);
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true;
|
2007-01-23 07:06:56 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// For first-line baselines, we have to consider scroll frames.
|
|
|
|
|
if (fType == nsGkAtoms::scrollFrame) {
|
2009-01-12 22:20:59 +03:00
|
|
|
|
nsIScrollableFrame *sFrame = do_QueryFrame(const_cast<nsIFrame*>(aFrame));
|
|
|
|
|
if (!sFrame) {
|
2007-01-23 07:06:56 +03:00
|
|
|
|
NS_NOTREACHED("not scroll frame");
|
|
|
|
|
}
|
2009-04-09 00:52:36 +04:00
|
|
|
|
LinePosition kidPosition;
|
2014-06-17 16:19:38 +04:00
|
|
|
|
if (GetFirstLinePosition(aWM,
|
|
|
|
|
sFrame->GetScrolledFrame(), &kidPosition)) {
|
2007-01-23 07:06:56 +03:00
|
|
|
|
// Consider only the border and padding that contributes to the
|
|
|
|
|
// kid's position, not the scrolling, so we get the initial
|
|
|
|
|
// position.
|
2014-06-17 16:19:38 +04:00
|
|
|
|
*aResult = kidPosition +
|
|
|
|
|
aFrame->GetLogicalUsedBorderAndPadding(aWM).BStart(aWM);
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true;
|
2007-01-23 07:06:56 +03:00
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2007-01-23 07:06:56 +03:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-05 06:40:19 +04:00
|
|
|
|
if (fType == nsGkAtoms::fieldSetFrame) {
|
|
|
|
|
LinePosition kidPosition;
|
2011-08-25 00:54:30 +04:00
|
|
|
|
nsIFrame* kid = aFrame->GetFirstPrincipalChild();
|
2010-08-05 06:40:19 +04:00
|
|
|
|
// kid might be a legend frame here, but that's ok.
|
2014-06-17 16:19:38 +04:00
|
|
|
|
if (GetFirstLinePosition(aWM, kid, &kidPosition)) {
|
|
|
|
|
*aResult = kidPosition +
|
2015-07-16 12:07:57 +03:00
|
|
|
|
kid->GetLogicalNormalPosition(aWM, aFrame->GetSize()).B(aWM);
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true;
|
2010-08-05 06:40:19 +04:00
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2010-08-05 06:40:19 +04:00
|
|
|
|
}
|
|
|
|
|
|
2007-01-23 07:06:56 +03:00
|
|
|
|
// No baseline.
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2007-01-23 07:06:56 +03: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-09 00:52:36 +04:00
|
|
|
|
LinePosition kidPosition;
|
2014-06-17 16:19:38 +04:00
|
|
|
|
if (GetFirstLinePosition(aWM, kid, &kidPosition)) {
|
|
|
|
|
//XXX Not sure if this is the correct value to use for container
|
|
|
|
|
// width here. It will only be used in vertical-rl layout,
|
|
|
|
|
// which we don't have full support and testing for yet.
|
2015-07-16 12:07:57 +03:00
|
|
|
|
const nsSize& containerSize = line->mContainerSize;
|
2014-06-17 16:19:38 +04:00
|
|
|
|
*aResult = kidPosition +
|
2015-07-16 12:07:57 +03:00
|
|
|
|
kid->GetLogicalNormalPosition(aWM, containerSize).B(aWM);
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true;
|
2007-01-23 07:06:56 +03:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// XXX Is this the right test? We have some bogus empty lines
|
|
|
|
|
// floating around, but IsEmpty is perhaps too weak.
|
2014-04-16 12:03:28 +04:00
|
|
|
|
if (line->BSize() != 0 || !line->IsEmpty()) {
|
2014-06-17 16:19:38 +04:00
|
|
|
|
nscoord bStart = line->BStart();
|
|
|
|
|
aResult->mBStart = bStart;
|
|
|
|
|
aResult->mBaseline = bStart + line->GetLogicalAscent();
|
|
|
|
|
aResult->mBEnd = bStart + line->BSize();
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true;
|
2007-01-23 07:06:56 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2007-01-23 07:06:56 +03:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
|
/* static */ bool
|
2014-06-17 16:19:38 +04:00
|
|
|
|
nsLayoutUtils::GetLastLineBaseline(WritingMode aWM,
|
|
|
|
|
const nsIFrame* aFrame, nscoord* aResult)
|
2007-01-23 07:06:56 +03:00
|
|
|
|
{
|
2008-07-14 02:10:23 +04:00
|
|
|
|
const nsBlockFrame* block = nsLayoutUtils::GetAsBlock(const_cast<nsIFrame*>(aFrame));
|
|
|
|
|
if (!block)
|
2007-01-23 07:06:56 +03:00
|
|
|
|
// No baseline. (We intentionally don't descend into scroll frames.)
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2007-01-23 07:06:56 +03: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;
|
2015-07-16 12:07:57 +03:00
|
|
|
|
const nsSize& containerSize = line->mContainerSize;
|
2014-06-17 16:19:38 +04:00
|
|
|
|
if (GetLastLineBaseline(aWM, kid, &kidBaseline)) {
|
2012-10-18 01:01:55 +04:00
|
|
|
|
// Ignore relative positioning for baseline calculations
|
2014-06-17 16:19:38 +04:00
|
|
|
|
*aResult = kidBaseline +
|
2015-07-16 12:07:57 +03:00
|
|
|
|
kid->GetLogicalNormalPosition(aWM, containerSize).B(aWM);
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true;
|
2007-01-23 07:06:56 +03: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.
|
2015-07-16 12:07:57 +03:00
|
|
|
|
*aResult = kid->GetLogicalNormalPosition(aWM, containerSize).B(aWM) +
|
2014-06-17 16:19:38 +04:00
|
|
|
|
kid->BSize(aWM);
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true;
|
2007-01-23 07:06:56 +03:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// XXX Is this the right test? We have some bogus empty lines
|
|
|
|
|
// floating around, but IsEmpty is perhaps too weak.
|
2014-04-16 12:03:28 +04:00
|
|
|
|
if (line->BSize() != 0 || !line->IsEmpty()) {
|
2014-06-17 16:19:38 +04:00
|
|
|
|
*aResult = line->BStart() + line->GetLogicalAscent();
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true;
|
2007-01-23 07:06:56 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2007-01-23 07:06:56 +03:00
|
|
|
|
}
|
2007-02-18 13:43:12 +03:00
|
|
|
|
|
2008-04-18 11:40:35 +04:00
|
|
|
|
static nscoord
|
2014-06-17 16:19:38 +04:00
|
|
|
|
CalculateBlockContentBEnd(WritingMode aWM, nsBlockFrame* aFrame)
|
2008-04-18 11:40:35 +04:00
|
|
|
|
{
|
|
|
|
|
NS_PRECONDITION(aFrame, "null ptr");
|
|
|
|
|
|
2014-06-17 16:19:38 +04:00
|
|
|
|
nscoord contentBEnd = 0;
|
2008-04-18 11:40:35 +04:00
|
|
|
|
|
|
|
|
|
for (nsBlockFrame::line_iterator line = aFrame->begin_lines(),
|
|
|
|
|
line_end = aFrame->end_lines();
|
|
|
|
|
line != line_end; ++line) {
|
|
|
|
|
if (line->IsBlock()) {
|
|
|
|
|
nsIFrame* child = line->mFirstChild;
|
2015-07-16 12:07:57 +03:00
|
|
|
|
const nsSize& containerSize = line->mContainerSize;
|
2014-06-17 16:19:38 +04:00
|
|
|
|
nscoord offset =
|
2015-07-16 12:07:57 +03:00
|
|
|
|
child->GetLogicalNormalPosition(aWM, containerSize).B(aWM);
|
2014-06-17 16:19:38 +04:00
|
|
|
|
contentBEnd =
|
|
|
|
|
std::max(contentBEnd,
|
|
|
|
|
nsLayoutUtils::CalculateContentBEnd(aWM, child) + offset);
|
2008-04-18 11:40:35 +04:00
|
|
|
|
}
|
|
|
|
|
else {
|
2014-06-17 16:19:38 +04:00
|
|
|
|
contentBEnd = std::max(contentBEnd, line->BEnd());
|
2008-04-18 11:40:35 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-17 16:19:38 +04:00
|
|
|
|
return contentBEnd;
|
2008-04-18 11:40:35 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* static */ nscoord
|
2014-06-17 16:19:38 +04:00
|
|
|
|
nsLayoutUtils::CalculateContentBEnd(WritingMode aWM, nsIFrame* aFrame)
|
2008-04-18 11:40:35 +04:00
|
|
|
|
{
|
|
|
|
|
NS_PRECONDITION(aFrame, "null ptr");
|
|
|
|
|
|
2014-06-17 16:19:38 +04:00
|
|
|
|
nscoord contentBEnd = aFrame->BSize(aWM);
|
2008-04-18 11:40:35 +04:00
|
|
|
|
|
2010-10-07 08:25:47 +04:00
|
|
|
|
// We want scrollable overflow rather than visual because this
|
|
|
|
|
// calculation is intended to affect layout.
|
2014-06-17 16:19:38 +04:00
|
|
|
|
LogicalSize overflowSize(aWM, aFrame->GetScrollableOverflowRect().Size());
|
|
|
|
|
if (overflowSize.BSize(aWM) > contentBEnd) {
|
2011-08-25 00:54:29 +04:00
|
|
|
|
nsIFrame::ChildListIDs skip(nsIFrame::kOverflowList |
|
|
|
|
|
nsIFrame::kExcessOverflowContainersList |
|
|
|
|
|
nsIFrame::kOverflowOutOfFlowList);
|
2008-04-18 11:40:35 +04:00
|
|
|
|
nsBlockFrame* blockFrame = GetAsBlock(aFrame);
|
2011-08-25 00:54:29 +04:00
|
|
|
|
if (blockFrame) {
|
2014-06-17 16:19:38 +04:00
|
|
|
|
contentBEnd =
|
|
|
|
|
std::max(contentBEnd, CalculateBlockContentBEnd(aWM, blockFrame));
|
2011-08-25 00:54:29 +04:00
|
|
|
|
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();
|
2014-06-17 16:19:38 +04:00
|
|
|
|
nscoord offset =
|
|
|
|
|
child->GetLogicalNormalPosition(aWM,
|
2015-07-16 12:07:57 +03:00
|
|
|
|
aFrame->GetSize()).B(aWM);
|
2014-06-17 16:19:38 +04:00
|
|
|
|
contentBEnd = std::max(contentBEnd,
|
|
|
|
|
CalculateContentBEnd(aWM, child) + offset);
|
2008-04-18 11:40:35 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-08-25 00:54:29 +04:00
|
|
|
|
}
|
2008-04-18 11:40:35 +04:00
|
|
|
|
}
|
2014-06-17 16:19:38 +04:00
|
|
|
|
return contentBEnd;
|
2008-04-18 11:40:35 +04:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-18 13:43:12 +03:00
|
|
|
|
/* static */ nsIFrame*
|
|
|
|
|
nsLayoutUtils::GetClosestLayer(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
nsIFrame* layer;
|
|
|
|
|
for (layer = aFrame; layer; layer = layer->GetParent()) {
|
2015-03-12 06:21:01 +03:00
|
|
|
|
if (layer->IsAbsPosContaininingBlock() ||
|
2007-02-18 13:43:12 +03:00
|
|
|
|
(layer->GetParent() &&
|
|
|
|
|
layer->GetParent()->GetType() == nsGkAtoms::scrollFrame))
|
|
|
|
|
break;
|
|
|
|
|
}
|
2007-02-20 03:26:53 +03:00
|
|
|
|
if (layer)
|
|
|
|
|
return layer;
|
2007-03-31 01:11:41 +04:00
|
|
|
|
return aFrame->PresContext()->PresShell()->FrameManager()->GetRootFrame();
|
2007-02-18 13:43:12 +03:00
|
|
|
|
}
|
2007-03-20 03:58:20 +03:00
|
|
|
|
|
2010-10-12 00:07:59 +04:00
|
|
|
|
GraphicsFilter
|
2009-04-10 17:41:59 +04:00
|
|
|
|
nsLayoutUtils::GetGraphicsFilterForFrame(nsIFrame* aForFrame)
|
2009-04-05 13:52:14 +04:00
|
|
|
|
{
|
2013-10-02 01:01:19 +04:00
|
|
|
|
GraphicsFilter defaultFilter = GraphicsFilter::FILTER_GOOD;
|
2013-03-07 09:13:13 +04:00
|
|
|
|
nsStyleContext *sc;
|
|
|
|
|
if (nsCSSRendering::IsCanvasFrame(aForFrame)) {
|
2013-03-07 20:03:49 +04:00
|
|
|
|
nsCSSRendering::FindBackground(aForFrame, &sc);
|
2013-03-07 09:13:13 +04:00
|
|
|
|
} else {
|
|
|
|
|
sc = aForFrame->StyleContext();
|
|
|
|
|
}
|
2009-04-10 17:41:59 +04:00
|
|
|
|
|
2013-03-07 09:13:13 +04:00
|
|
|
|
switch (sc->StyleSVG()->mImageRendering) {
|
2009-04-05 13:52:14 +04:00
|
|
|
|
case NS_STYLE_IMAGE_RENDERING_OPTIMIZESPEED:
|
2013-10-02 01:01:19 +04:00
|
|
|
|
return GraphicsFilter::FILTER_FAST;
|
2009-04-05 13:52:14 +04:00
|
|
|
|
case NS_STYLE_IMAGE_RENDERING_OPTIMIZEQUALITY:
|
2013-10-02 01:01:19 +04:00
|
|
|
|
return GraphicsFilter::FILTER_BEST;
|
2009-04-05 13:52:14 +04:00
|
|
|
|
case NS_STYLE_IMAGE_RENDERING_CRISPEDGES:
|
2013-10-02 01:01:19 +04:00
|
|
|
|
return GraphicsFilter::FILTER_NEAREST;
|
2009-04-05 13:52:14 +04:00
|
|
|
|
default:
|
2010-04-20 20:36:00 +04:00
|
|
|
|
return defaultFilter;
|
2009-04-05 13:52:14 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-18 10:48:46 +03: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-05 01:01:21 +03:00
|
|
|
|
static gfxPoint
|
2008-12-03 04:32:18 +03:00
|
|
|
|
MapToFloatImagePixels(const gfxSize& aSize,
|
|
|
|
|
const gfxRect& aDest, const gfxPoint& aPt)
|
2008-11-05 01:01:21 +03:00
|
|
|
|
{
|
2011-04-19 07:07:21 +04:00
|
|
|
|
return gfxPoint(((aPt.x - aDest.X())*aSize.width)/aDest.Width(),
|
|
|
|
|
((aPt.y - aDest.Y())*aSize.height)/aDest.Height());
|
2008-11-05 01:01:21 +03:00
|
|
|
|
}
|
|
|
|
|
|
2008-11-18 10:48:46 +03: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-03 04:32:18 +03:00
|
|
|
|
MapToFloatUserPixels(const gfxSize& aSize,
|
2008-11-18 10:48:46 +03:00
|
|
|
|
const gfxRect& aDest, const gfxPoint& aPt)
|
|
|
|
|
{
|
2011-04-19 07:07:21 +04:00
|
|
|
|
return gfxPoint(aPt.x*aDest.Width()/aSize.width + aDest.X(),
|
|
|
|
|
aPt.y*aDest.Height()/aSize.height + aDest.Y());
|
2008-11-18 10:48:46 +03:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-08 02:20:35 +04:00
|
|
|
|
/* static */ gfxRect
|
2012-08-22 19:56:38 +04:00
|
|
|
|
nsLayoutUtils::RectToGfxRect(const nsRect& aRect, int32_t aAppUnitsPerDevPixel)
|
2010-07-01 20:43:06 +04:00
|
|
|
|
{
|
|
|
|
|
return gfxRect(gfxFloat(aRect.x) / aAppUnitsPerDevPixel,
|
|
|
|
|
gfxFloat(aRect.y) / aAppUnitsPerDevPixel,
|
|
|
|
|
gfxFloat(aRect.width) / aAppUnitsPerDevPixel,
|
|
|
|
|
gfxFloat(aRect.height) / aAppUnitsPerDevPixel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct SnappedImageDrawingParameters {
|
2014-08-23 00:12:38 +04:00
|
|
|
|
// A transform from image space to device space.
|
|
|
|
|
gfxMatrix imageSpaceToDeviceSpace;
|
|
|
|
|
// The size at which the image should be drawn (which may not be its
|
|
|
|
|
// intrinsic size due to, for example, HQ scaling).
|
|
|
|
|
nsIntSize size;
|
|
|
|
|
// The region in tiled image space which will be drawn, with an associated
|
|
|
|
|
// region to which sampling should be restricted.
|
|
|
|
|
ImageRegion region;
|
2014-12-16 02:44:13 +03:00
|
|
|
|
// The default viewport size for SVG images, which we use unless a different
|
|
|
|
|
// one has been explicitly specified. This is the same as |size| except that
|
|
|
|
|
// it does not take into account any transformation on the gfxContext we're
|
|
|
|
|
// drawing to - for example, CSS transforms are not taken into account.
|
2015-04-03 22:48:12 +03:00
|
|
|
|
CSSIntSize svgViewportSize;
|
2014-08-23 00:12:38 +04:00
|
|
|
|
// Whether there's anything to draw at all.
|
|
|
|
|
bool shouldDraw;
|
2010-07-01 20:43:06 +04:00
|
|
|
|
|
|
|
|
|
SnappedImageDrawingParameters()
|
2014-08-23 00:12:38 +04:00
|
|
|
|
: region(ImageRegion::Empty())
|
|
|
|
|
, shouldDraw(false)
|
2010-07-01 20:43:06 +04:00
|
|
|
|
{}
|
|
|
|
|
|
2014-08-23 00:12:38 +04:00
|
|
|
|
SnappedImageDrawingParameters(const gfxMatrix& aImageSpaceToDeviceSpace,
|
|
|
|
|
const nsIntSize& aSize,
|
2014-12-16 02:44:13 +03:00
|
|
|
|
const ImageRegion& aRegion,
|
2015-04-03 22:48:12 +03:00
|
|
|
|
const CSSIntSize& aSVGViewportSize)
|
2014-08-23 00:12:38 +04:00
|
|
|
|
: imageSpaceToDeviceSpace(aImageSpaceToDeviceSpace)
|
|
|
|
|
, size(aSize)
|
|
|
|
|
, region(aRegion)
|
2014-12-16 02:44:13 +03:00
|
|
|
|
, svgViewportSize(aSVGViewportSize)
|
2014-08-23 00:12:38 +04:00
|
|
|
|
, shouldDraw(true)
|
2010-07-01 20:43:06 +04:00
|
|
|
|
{}
|
|
|
|
|
};
|
|
|
|
|
|
2014-08-23 00:12:38 +04:00
|
|
|
|
/**
|
|
|
|
|
* Given two axis-aligned rectangles, returns the transformation that maps the
|
|
|
|
|
* first onto the second.
|
|
|
|
|
*
|
|
|
|
|
* @param aFrom The rect to be transformed.
|
|
|
|
|
* @param aTo The rect that aFrom should be mapped onto by the transformation.
|
|
|
|
|
*/
|
|
|
|
|
static gfxMatrix
|
|
|
|
|
TransformBetweenRects(const gfxRect& aFrom, const gfxRect& aTo)
|
|
|
|
|
{
|
|
|
|
|
gfxSize scale(aTo.width / aFrom.width,
|
|
|
|
|
aTo.height / aFrom.height);
|
|
|
|
|
gfxPoint translation(aTo.x - aFrom.x * scale.width,
|
|
|
|
|
aTo.y - aFrom.y * scale.height);
|
|
|
|
|
return gfxMatrix(scale.width, 0, 0, scale.height,
|
|
|
|
|
translation.x, translation.y);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-18 13:48:38 +04:00
|
|
|
|
static nsRect
|
|
|
|
|
TileNearRect(const nsRect& aAnyTile, const nsRect& aTargetRect)
|
|
|
|
|
{
|
|
|
|
|
nsPoint distance = aTargetRect.TopLeft() - aAnyTile.TopLeft();
|
|
|
|
|
return aAnyTile + nsPoint(distance.x / aAnyTile.width * aAnyTile.width,
|
|
|
|
|
distance.y / aAnyTile.height * aAnyTile.height);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-29 05:08:40 +03:00
|
|
|
|
static gfxFloat
|
|
|
|
|
StableRound(gfxFloat aValue)
|
|
|
|
|
{
|
|
|
|
|
// Values slightly less than 0.5 should round up like 0.5 would; we're
|
|
|
|
|
// assuming they were meant to be 0.5.
|
|
|
|
|
return floor(aValue + 0.5001);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gfxPoint
|
|
|
|
|
StableRound(const gfxPoint& aPoint)
|
|
|
|
|
{
|
|
|
|
|
return gfxPoint(StableRound(aPoint.x), StableRound(aPoint.y));
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-01 20:43:06 +04:00
|
|
|
|
/**
|
|
|
|
|
* 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 19:56:38 +04:00
|
|
|
|
int32_t aAppUnitsPerDevPixel,
|
2010-07-01 20:43:06 +04:00
|
|
|
|
const nsRect aDest,
|
|
|
|
|
const nsRect aFill,
|
|
|
|
|
const nsPoint aAnchor,
|
|
|
|
|
const nsRect aDirty,
|
2014-08-23 00:12:38 +04:00
|
|
|
|
imgIContainer* aImage,
|
|
|
|
|
GraphicsFilter aGraphicsFilter,
|
|
|
|
|
uint32_t aImageFlags)
|
2008-11-05 01:01:21 +03:00
|
|
|
|
{
|
2014-08-23 00:12:38 +04:00
|
|
|
|
if (aDest.IsEmpty() || aFill.IsEmpty())
|
2010-07-01 20:43:06 +04:00
|
|
|
|
return SnappedImageDrawingParameters();
|
|
|
|
|
|
2014-07-18 13:48:38 +04:00
|
|
|
|
// Avoid unnecessarily large offsets.
|
|
|
|
|
bool doTile = !aDest.Contains(aFill);
|
2015-04-22 23:04:04 +03:00
|
|
|
|
nsRect appUnitDest = doTile ? TileNearRect(aDest, aFill.Intersect(aDirty))
|
|
|
|
|
: aDest;
|
|
|
|
|
nsPoint anchor = aAnchor + (appUnitDest.TopLeft() - aDest.TopLeft());
|
2014-07-18 13:48:38 +04:00
|
|
|
|
|
2010-09-08 02:20:35 +04:00
|
|
|
|
gfxRect devPixelDest =
|
2015-04-22 23:04:04 +03:00
|
|
|
|
nsLayoutUtils::RectToGfxRect(appUnitDest, aAppUnitsPerDevPixel);
|
2010-09-08 02:20:35 +04:00
|
|
|
|
gfxRect devPixelFill =
|
|
|
|
|
nsLayoutUtils::RectToGfxRect(aFill, aAppUnitsPerDevPixel);
|
|
|
|
|
gfxRect devPixelDirty =
|
|
|
|
|
nsLayoutUtils::RectToGfxRect(aDirty, aAppUnitsPerDevPixel);
|
2007-03-20 03:58:20 +03:00
|
|
|
|
|
2012-09-04 02:32:20 +04:00
|
|
|
|
gfxMatrix currentMatrix = aCtx->CurrentMatrix();
|
2012-12-05 03:34:19 +04:00
|
|
|
|
gfxRect fill = devPixelFill;
|
2015-04-22 23:04:04 +03:00
|
|
|
|
gfxRect dest = devPixelDest;
|
2012-12-05 03:34:19 +04:00
|
|
|
|
bool didSnap;
|
|
|
|
|
// Snap even if we have a scale in the context. But don't snap if
|
|
|
|
|
// we have something that's not translation+scale, or if the scale flips in
|
|
|
|
|
// the X or Y direction, because snapped image drawing can't handle that yet.
|
|
|
|
|
if (!currentMatrix.HasNonAxisAlignedTransform() &&
|
2014-06-17 21:35:51 +04:00
|
|
|
|
currentMatrix._11 > 0.0 && currentMatrix._22 > 0.0 &&
|
2015-04-22 23:04:04 +03:00
|
|
|
|
aCtx->UserToDevicePixelSnapped(fill, true) &&
|
|
|
|
|
aCtx->UserToDevicePixelSnapped(dest, true)) {
|
|
|
|
|
// We snapped. On this code path, |fill| and |dest| take into account
|
|
|
|
|
// currentMatrix's transform.
|
2012-12-05 03:34:19 +04:00
|
|
|
|
didSnap = true;
|
|
|
|
|
} else {
|
2015-04-22 23:04:04 +03:00
|
|
|
|
// We didn't snap. On this code path, |fill| and |dest| do not take into
|
|
|
|
|
// account currentMatrix's transform.
|
2012-09-04 02:32:20 +04:00
|
|
|
|
didSnap = false;
|
|
|
|
|
fill = devPixelFill;
|
2015-04-22 23:04:04 +03:00
|
|
|
|
dest = devPixelDest;
|
2015-03-28 06:07:31 +03:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-22 23:04:04 +03:00
|
|
|
|
// If we snapped above, |dest| already takes into account |currentMatrix|'s scale
|
|
|
|
|
// and has integer coordinates. If not, we need these properties to compute
|
|
|
|
|
// the optimal drawn image size, so compute |snappedDestSize| here.
|
|
|
|
|
gfxSize snappedDestSize = dest.Size();
|
|
|
|
|
if (!didSnap) {
|
|
|
|
|
gfxSize scaleFactors = currentMatrix.ScaleFactors(true);
|
|
|
|
|
snappedDestSize.Scale(scaleFactors.width, scaleFactors.height);
|
|
|
|
|
snappedDestSize.width = NS_round(snappedDestSize.width);
|
|
|
|
|
snappedDestSize.height = NS_round(snappedDestSize.height);
|
2015-04-22 05:23:10 +03:00
|
|
|
|
}
|
2014-09-17 03:18:49 +04:00
|
|
|
|
|
2015-04-22 23:04:04 +03:00
|
|
|
|
// We need to be sure that this is at least one pixel in width and height,
|
|
|
|
|
// or we'll end up drawing nothing even if we have a nonempty fill.
|
|
|
|
|
snappedDestSize.width = std::max(snappedDestSize.width, 1.0);
|
|
|
|
|
snappedDestSize.height = std::max(snappedDestSize.height, 1.0);
|
|
|
|
|
|
|
|
|
|
// Bail if we're not going to end up drawing anything.
|
|
|
|
|
if (fill.IsEmpty() || snappedDestSize.IsEmpty()) {
|
|
|
|
|
return SnappedImageDrawingParameters();
|
|
|
|
|
}
|
2015-04-22 14:14:35 +03:00
|
|
|
|
|
2014-08-23 00:12:38 +04:00
|
|
|
|
nsIntSize intImageSize =
|
2015-04-22 23:04:04 +03:00
|
|
|
|
aImage->OptimalImageSizeForDest(snappedDestSize,
|
2014-08-23 00:12:38 +04:00
|
|
|
|
imgIContainer::FRAME_CURRENT,
|
|
|
|
|
aGraphicsFilter, aImageFlags);
|
|
|
|
|
gfxSize imageSize(intImageSize.width, intImageSize.height);
|
2007-03-20 03:58:20 +03:00
|
|
|
|
|
2015-04-22 23:04:04 +03:00
|
|
|
|
// XXX(seth): May be buggy; see bug 1151016.
|
2015-04-03 22:48:12 +03:00
|
|
|
|
CSSIntSize svgViewportSize = currentMatrix.IsIdentity()
|
|
|
|
|
? CSSIntSize(intImageSize.width, intImageSize.height)
|
2015-04-22 23:04:04 +03:00
|
|
|
|
: CSSIntSize(devPixelDest.width, devPixelDest.height);
|
2014-12-16 02:44:13 +03:00
|
|
|
|
|
2008-11-05 01:01:21 +03:00
|
|
|
|
// Compute the set of pixels that would be sampled by an ideal rendering
|
|
|
|
|
gfxPoint subimageTopLeft =
|
2008-12-03 05:02:29 +03:00
|
|
|
|
MapToFloatImagePixels(imageSize, devPixelDest, devPixelFill.TopLeft());
|
2008-11-05 01:01:21 +03:00
|
|
|
|
gfxPoint subimageBottomRight =
|
2008-12-03 05:02:29 +03:00
|
|
|
|
MapToFloatImagePixels(imageSize, devPixelDest, devPixelFill.BottomRight());
|
2014-08-23 00:12:38 +04:00
|
|
|
|
gfxRect subimage;
|
|
|
|
|
subimage.MoveTo(NSToIntFloor(subimageTopLeft.x),
|
|
|
|
|
NSToIntFloor(subimageTopLeft.y));
|
|
|
|
|
subimage.SizeTo(NSToIntCeil(subimageBottomRight.x) - subimage.x,
|
|
|
|
|
NSToIntCeil(subimageBottomRight.y) - subimage.y);
|
|
|
|
|
|
|
|
|
|
gfxMatrix transform;
|
|
|
|
|
gfxMatrix invTransform;
|
|
|
|
|
|
2015-04-22 23:04:04 +03:00
|
|
|
|
bool anchorAtUpperLeft = anchor.x == appUnitDest.x &&
|
|
|
|
|
anchor.y == appUnitDest.y;
|
|
|
|
|
bool exactlyOneImageCopy = aFill.IsEqualEdges(appUnitDest);
|
2014-08-23 00:12:38 +04:00
|
|
|
|
if (anchorAtUpperLeft && exactlyOneImageCopy) {
|
|
|
|
|
// The simple case: we can ignore the anchor point and compute the
|
|
|
|
|
// transformation from the sampled region (the subimage) to the fill rect.
|
|
|
|
|
// This approach is preferable when it works since it tends to produce
|
|
|
|
|
// less numerical error.
|
|
|
|
|
transform = TransformBetweenRects(subimage, fill);
|
|
|
|
|
invTransform = TransformBetweenRects(fill, subimage);
|
|
|
|
|
} else {
|
|
|
|
|
// The more complicated case: we compute the transformation from the
|
|
|
|
|
// image rect positioned at the image space anchor point to the dest rect
|
|
|
|
|
// positioned at the device space anchor point.
|
|
|
|
|
|
|
|
|
|
// Compute the anchor point in both device space and image space. This
|
|
|
|
|
// code assumes that pixel-based devices have one pixel per device unit!
|
|
|
|
|
gfxPoint anchorPoint(gfxFloat(anchor.x)/aAppUnitsPerDevPixel,
|
|
|
|
|
gfxFloat(anchor.y)/aAppUnitsPerDevPixel);
|
|
|
|
|
gfxPoint imageSpaceAnchorPoint =
|
|
|
|
|
MapToFloatImagePixels(imageSize, devPixelDest, anchorPoint);
|
|
|
|
|
|
|
|
|
|
if (didSnap) {
|
2014-10-29 05:08:40 +03:00
|
|
|
|
imageSpaceAnchorPoint = StableRound(imageSpaceAnchorPoint);
|
2014-08-23 00:12:38 +04:00
|
|
|
|
anchorPoint = imageSpaceAnchorPoint;
|
|
|
|
|
anchorPoint = MapToFloatUserPixels(imageSize, devPixelDest, anchorPoint);
|
|
|
|
|
anchorPoint = currentMatrix.Transform(anchorPoint);
|
2014-10-29 05:08:40 +03:00
|
|
|
|
anchorPoint = StableRound(anchorPoint);
|
2014-08-23 00:12:38 +04:00
|
|
|
|
}
|
2008-11-05 01:01:21 +03:00
|
|
|
|
|
2015-04-22 23:04:04 +03:00
|
|
|
|
// Compute an unsnapped version of the dest rect's size. We continue to
|
|
|
|
|
// follow the pattern that we take |currentMatrix| into account only if
|
|
|
|
|
// |didSnap| is true.
|
|
|
|
|
gfxSize unsnappedDestSize
|
|
|
|
|
= didSnap ? devPixelDest.Size() * currentMatrix.ScaleFactors(true)
|
|
|
|
|
: devPixelDest.Size();
|
|
|
|
|
|
|
|
|
|
gfxRect anchoredDestRect(anchorPoint, unsnappedDestSize);
|
2014-08-23 00:12:38 +04:00
|
|
|
|
gfxRect anchoredImageRect(imageSpaceAnchorPoint, imageSize);
|
2015-02-17 09:16:13 +03:00
|
|
|
|
|
|
|
|
|
// Calculate anchoredDestRect with snapped fill rect when the devPixelFill rect
|
|
|
|
|
// corresponds to just a single tile in that direction
|
|
|
|
|
if (fill.Width() != devPixelFill.Width() &&
|
|
|
|
|
devPixelDest.x == devPixelFill.x &&
|
|
|
|
|
devPixelDest.XMost() == devPixelFill.XMost()) {
|
|
|
|
|
anchoredDestRect.width = fill.width;
|
|
|
|
|
}
|
|
|
|
|
if (fill.Height() != devPixelFill.Height() &&
|
|
|
|
|
devPixelDest.y == devPixelFill.y &&
|
|
|
|
|
devPixelDest.YMost() == devPixelFill.YMost()) {
|
|
|
|
|
anchoredDestRect.height = fill.height;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-23 00:12:38 +04:00
|
|
|
|
transform = TransformBetweenRects(anchoredImageRect, anchoredDestRect);
|
|
|
|
|
invTransform = TransformBetweenRects(anchoredDestRect, anchoredImageRect);
|
2008-11-05 01:01:21 +03:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-23 00:12:38 +04:00
|
|
|
|
// If the 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.
|
|
|
|
|
// Also, if 'didSnap' is false then rounding out 'devPixelDirty' might not
|
2008-12-02 23:46:44 +03:00
|
|
|
|
// produce pixel-aligned coordinates, which would also break the values
|
|
|
|
|
// computed for edge pixels.
|
2014-08-23 00:12:38 +04:00
|
|
|
|
if (didSnap && !invTransform.HasNonIntegerTranslation()) {
|
|
|
|
|
// This form of Transform is safe to call since non-axis-aligned
|
|
|
|
|
// transforms wouldn't be snapped.
|
|
|
|
|
devPixelDirty = currentMatrix.Transform(devPixelDirty);
|
2010-07-01 20:43:06 +04:00
|
|
|
|
devPixelDirty.RoundOut();
|
2014-08-23 00:12:38 +04:00
|
|
|
|
fill = fill.Intersect(devPixelDirty);
|
2008-12-02 23:46:44 +03:00
|
|
|
|
}
|
2014-08-23 00:12:38 +04:00
|
|
|
|
if (fill.IsEmpty())
|
2010-07-01 20:43:06 +04:00
|
|
|
|
return SnappedImageDrawingParameters();
|
|
|
|
|
|
2014-08-23 00:12:38 +04:00
|
|
|
|
gfxRect imageSpaceFill(didSnap ? invTransform.Transform(fill)
|
|
|
|
|
: invTransform.TransformBounds(fill));
|
|
|
|
|
|
|
|
|
|
// If we didn't snap, we need to post-multiply the matrix on the context to
|
|
|
|
|
// get the final matrix we'll draw with, because we didn't take it into
|
|
|
|
|
// account when computing the matrices above.
|
|
|
|
|
if (!didSnap) {
|
|
|
|
|
transform = transform * currentMatrix;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImageRegion region =
|
|
|
|
|
ImageRegion::CreateWithSamplingRestriction(imageSpaceFill, subimage);
|
2014-12-16 02:44:13 +03:00
|
|
|
|
|
|
|
|
|
return SnappedImageDrawingParameters(transform, intImageSize,
|
|
|
|
|
region, svgViewportSize);
|
2010-07-01 20:43:06 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-02-05 00:50:56 +03:00
|
|
|
|
static DrawResult
|
2014-11-01 13:45:09 +03:00
|
|
|
|
DrawImageInternal(gfxContext& aContext,
|
2014-06-20 10:42:30 +04:00
|
|
|
|
nsPresContext* aPresContext,
|
2013-03-01 00:22:43 +04:00
|
|
|
|
imgIContainer* aImage,
|
|
|
|
|
GraphicsFilter aGraphicsFilter,
|
|
|
|
|
const nsRect& aDest,
|
|
|
|
|
const nsRect& aFill,
|
|
|
|
|
const nsPoint& aAnchor,
|
|
|
|
|
const nsRect& aDirty,
|
|
|
|
|
const SVGImageContext* aSVGContext,
|
|
|
|
|
uint32_t aImageFlags)
|
2010-07-01 20:43:06 +04:00
|
|
|
|
{
|
2014-06-26 11:40:12 +04:00
|
|
|
|
if (aPresContext->Type() == nsPresContext::eContext_Print) {
|
|
|
|
|
// We want vector images to be passed on as vector commands, not a raster
|
|
|
|
|
// image.
|
|
|
|
|
aImageFlags |= imgIContainer::FLAG_BYPASS_SURFACE_CACHE;
|
|
|
|
|
}
|
2012-04-18 02:04:15 +04:00
|
|
|
|
if (aDest.Contains(aFill)) {
|
|
|
|
|
aImageFlags |= imgIContainer::FLAG_CLAMP;
|
|
|
|
|
}
|
2014-06-20 10:42:30 +04:00
|
|
|
|
int32_t appUnitsPerDevPixel =
|
|
|
|
|
aPresContext->AppUnitsPerDevPixel();
|
2010-07-01 20:43:06 +04:00
|
|
|
|
|
2014-08-23 00:12:38 +04:00
|
|
|
|
SnappedImageDrawingParameters params =
|
2014-11-01 13:45:09 +03:00
|
|
|
|
ComputeSnappedImageDrawingParameters(&aContext, appUnitsPerDevPixel, aDest,
|
2014-08-23 00:12:38 +04:00
|
|
|
|
aFill, aAnchor, aDirty, aImage,
|
|
|
|
|
aGraphicsFilter, aImageFlags);
|
2010-07-01 20:43:06 +04:00
|
|
|
|
|
2015-02-05 00:50:56 +03:00
|
|
|
|
if (!params.shouldDraw) {
|
|
|
|
|
return DrawResult::SUCCESS;
|
|
|
|
|
}
|
2008-12-02 23:46:44 +03:00
|
|
|
|
|
2014-11-01 13:45:09 +03:00
|
|
|
|
gfxContextMatrixAutoSaveRestore contextMatrixRestorer(&aContext);
|
|
|
|
|
aContext.SetMatrix(params.imageSpaceToDeviceSpace);
|
2014-08-23 00:12:38 +04:00
|
|
|
|
|
2014-12-16 02:44:13 +03:00
|
|
|
|
Maybe<SVGImageContext> svgContext = ToMaybe(aSVGContext);
|
|
|
|
|
if (!svgContext) {
|
|
|
|
|
// Use the default viewport.
|
|
|
|
|
svgContext = Some(SVGImageContext(params.svgViewportSize, Nothing()));
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-05 00:50:56 +03:00
|
|
|
|
return aImage->Draw(&aContext, params.size, params.region,
|
|
|
|
|
imgIContainer::FRAME_CURRENT, aGraphicsFilter,
|
|
|
|
|
svgContext, aImageFlags);
|
2008-11-05 01:01:21 +03:00
|
|
|
|
}
|
2007-03-20 03:58:20 +03:00
|
|
|
|
|
2015-02-05 00:50:56 +03:00
|
|
|
|
/* static */ DrawResult
|
2014-11-01 13:45:09 +03:00
|
|
|
|
nsLayoutUtils::DrawSingleUnscaledImage(gfxContext& aContext,
|
2014-06-20 10:42:30 +04:00
|
|
|
|
nsPresContext* aPresContext,
|
2009-07-28 03:48:13 +04:00
|
|
|
|
imgIContainer* aImage,
|
2010-10-12 00:08:07 +04:00
|
|
|
|
GraphicsFilter aGraphicsFilter,
|
2009-07-28 03:48:13 +04:00
|
|
|
|
const nsPoint& aDest,
|
2010-10-12 00:08:07 +04:00
|
|
|
|
const nsRect* aDirty,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t aImageFlags,
|
2009-07-28 03:48:13 +04:00
|
|
|
|
const nsRect* aSourceArea)
|
|
|
|
|
{
|
2015-04-03 22:48:12 +03:00
|
|
|
|
CSSIntSize imageSize;
|
2009-07-28 03:48:13 +04:00
|
|
|
|
aImage->GetWidth(&imageSize.width);
|
|
|
|
|
aImage->GetHeight(&imageSize.height);
|
2015-02-05 00:50:56 +03:00
|
|
|
|
if (imageSize.width < 1 || imageSize.height < 1) {
|
|
|
|
|
NS_WARNING("Image width or height is non-positive");
|
|
|
|
|
return DrawResult::TEMPORARY_ERROR;
|
|
|
|
|
}
|
2008-11-05 01:01:21 +03:00
|
|
|
|
|
2015-04-03 22:48:12 +03:00
|
|
|
|
nsSize size(CSSPixel::ToAppUnits(imageSize));
|
2008-11-05 01:01:21 +03:00
|
|
|
|
nsRect source;
|
|
|
|
|
if (aSourceArea) {
|
|
|
|
|
source = *aSourceArea;
|
|
|
|
|
} else {
|
2009-01-30 10:33:57 +03:00
|
|
|
|
source.SizeTo(size);
|
2007-03-20 03:58:20 +03:00
|
|
|
|
}
|
|
|
|
|
|
2009-01-30 10:33:57 +03:00
|
|
|
|
nsRect dest(aDest - source.TopLeft(), size);
|
2008-11-05 01:01:21 +03:00
|
|
|
|
nsRect fill(aDest, source.Size());
|
2008-11-10 10:24:21 +03: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);
|
2014-11-01 13:45:09 +03:00
|
|
|
|
return DrawImageInternal(aContext, aPresContext,
|
2014-06-20 10:42:30 +04:00
|
|
|
|
aImage, aGraphicsFilter,
|
2010-10-12 00:08:07 +04:00
|
|
|
|
dest, fill, aDest, aDirty ? *aDirty : dest,
|
2014-08-23 00:12:38 +04:00
|
|
|
|
nullptr, aImageFlags);
|
2008-11-05 01:01:21 +03:00
|
|
|
|
}
|
2010-04-27 20:15:01 +04:00
|
|
|
|
|
2015-02-05 00:50:56 +03:00
|
|
|
|
/* static */ DrawResult
|
2014-11-01 13:45:09 +03:00
|
|
|
|
nsLayoutUtils::DrawSingleImage(gfxContext& aContext,
|
2014-06-20 10:42:30 +04:00
|
|
|
|
nsPresContext* aPresContext,
|
2013-03-01 00:22:43 +04:00
|
|
|
|
imgIContainer* aImage,
|
|
|
|
|
GraphicsFilter aGraphicsFilter,
|
|
|
|
|
const nsRect& aDest,
|
|
|
|
|
const nsRect& aDirty,
|
|
|
|
|
const SVGImageContext* aSVGContext,
|
|
|
|
|
uint32_t aImageFlags,
|
2014-11-22 05:25:46 +03:00
|
|
|
|
const nsPoint* aAnchorPoint,
|
2013-03-01 00:22:43 +04:00
|
|
|
|
const nsRect* aSourceArea)
|
2009-07-28 03:48:13 +04:00
|
|
|
|
{
|
2014-10-23 02:41:14 +04:00
|
|
|
|
nscoord appUnitsPerCSSPixel = nsDeviceContext::AppUnitsPerCSSPixel();
|
2015-03-30 18:35:47 +03:00
|
|
|
|
CSSIntSize pixelImageSize(ComputeSizeForDrawingWithFallback(aImage, aDest.Size()));
|
2015-02-05 00:50:56 +03:00
|
|
|
|
if (pixelImageSize.width < 1 || pixelImageSize.height < 1) {
|
|
|
|
|
NS_WARNING("Image width or height is non-positive");
|
|
|
|
|
return DrawResult::TEMPORARY_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-03 22:48:12 +03:00
|
|
|
|
nsSize imageSize(CSSPixel::ToAppUnits(pixelImageSize));
|
2008-11-05 01:01:21 +03:00
|
|
|
|
nsRect source;
|
2014-08-23 00:12:38 +04:00
|
|
|
|
nsCOMPtr<imgIContainer> image;
|
2008-11-05 01:01:21 +03:00
|
|
|
|
if (aSourceArea) {
|
|
|
|
|
source = *aSourceArea;
|
2014-08-23 00:12:38 +04:00
|
|
|
|
nsIntRect subRect(source.x, source.y, source.width, source.height);
|
2014-10-23 02:41:14 +04:00
|
|
|
|
subRect.ScaleInverseRoundOut(appUnitsPerCSSPixel);
|
2014-08-23 00:12:38 +04:00
|
|
|
|
image = ImageOps::Clip(aImage, subRect);
|
2014-10-23 02:41:14 +04:00
|
|
|
|
|
|
|
|
|
nsRect imageRect;
|
|
|
|
|
imageRect.SizeTo(imageSize);
|
|
|
|
|
nsRect clippedSource = imageRect.Intersect(source);
|
|
|
|
|
|
|
|
|
|
source -= clippedSource.TopLeft();
|
|
|
|
|
imageSize = clippedSource.Size();
|
2008-11-05 01:01:21 +03:00
|
|
|
|
} else {
|
2014-10-23 02:41:14 +04:00
|
|
|
|
source.SizeTo(imageSize);
|
2014-08-23 00:12:38 +04:00
|
|
|
|
image = aImage;
|
2007-03-20 03:58:20 +03:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-23 02:41:14 +04:00
|
|
|
|
nsRect dest = GetWholeImageDestination(imageSize, source, aDest);
|
|
|
|
|
|
2008-11-10 10:24:21 +03: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;
|
2014-10-13 04:39:44 +04:00
|
|
|
|
fill.IntersectRect(aDest, dest);
|
2014-11-01 13:45:09 +03:00
|
|
|
|
return DrawImageInternal(aContext, aPresContext, image,
|
2014-11-22 05:25:46 +03:00
|
|
|
|
aGraphicsFilter, dest, fill,
|
|
|
|
|
aAnchorPoint ? *aAnchorPoint : fill.TopLeft(),
|
2014-08-23 00:12:38 +04:00
|
|
|
|
aDirty, aSVGContext, aImageFlags);
|
2009-01-30 10:33:57 +03:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-09 00:40:39 +04:00
|
|
|
|
/* static */ void
|
|
|
|
|
nsLayoutUtils::ComputeSizeForDrawing(imgIContainer *aImage,
|
2015-03-30 18:35:47 +03:00
|
|
|
|
CSSIntSize& aImageSize, /*outparam*/
|
2011-01-13 13:40:12 +03:00
|
|
|
|
nsSize& aIntrinsicRatio, /*outparam*/
|
|
|
|
|
bool& aGotWidth, /*outparam*/
|
|
|
|
|
bool& aGotHeight /*outparam*/)
|
2010-09-09 00:40:39 +04:00
|
|
|
|
{
|
|
|
|
|
aGotWidth = NS_SUCCEEDED(aImage->GetWidth(&aImageSize.width));
|
|
|
|
|
aGotHeight = NS_SUCCEEDED(aImage->GetHeight(&aImageSize.height));
|
2013-01-11 07:38:34 +04:00
|
|
|
|
bool gotRatio = NS_SUCCEEDED(aImage->GetIntrinsicRatio(&aIntrinsicRatio));
|
2010-09-09 00:40:39 +04:00
|
|
|
|
|
2013-01-11 07:38:34 +04:00
|
|
|
|
if (!(aGotWidth && aGotHeight) && !gotRatio) {
|
|
|
|
|
// We hit an error (say, because the image failed to load or couldn't be
|
|
|
|
|
// decoded) and should return zero size.
|
2011-01-13 13:40:12 +03:00
|
|
|
|
aGotWidth = aGotHeight = true;
|
2015-03-30 18:35:47 +03:00
|
|
|
|
aImageSize = CSSIntSize(0, 0);
|
2011-01-13 13:40:12 +03:00
|
|
|
|
aIntrinsicRatio = nsSize(0, 0);
|
2010-09-09 00:40:39 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-30 18:35:47 +03:00
|
|
|
|
/* static */ CSSIntSize
|
2014-08-23 00:12:38 +04:00
|
|
|
|
nsLayoutUtils::ComputeSizeForDrawingWithFallback(imgIContainer* aImage,
|
|
|
|
|
const nsSize& aFallbackSize)
|
2009-01-30 10:33:57 +03:00
|
|
|
|
{
|
2015-03-30 18:35:47 +03:00
|
|
|
|
CSSIntSize imageSize;
|
2011-01-13 13:40:12 +03:00
|
|
|
|
nsSize imageRatio;
|
|
|
|
|
bool gotHeight, gotWidth;
|
|
|
|
|
ComputeSizeForDrawing(aImage, imageSize, imageRatio, gotWidth, gotHeight);
|
|
|
|
|
|
2014-08-23 00:12:38 +04:00
|
|
|
|
// If we didn't get both width and height, try to compute them using the
|
|
|
|
|
// intrinsic ratio of the image.
|
2011-01-13 13:40:12 +03:00
|
|
|
|
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-09 00:40:39 +04:00
|
|
|
|
|
2014-08-23 00:12:38 +04:00
|
|
|
|
// If we still don't have a width or height, just use the fallback size the
|
|
|
|
|
// caller provided.
|
2010-09-09 00:40:39 +04:00
|
|
|
|
if (!gotWidth) {
|
2014-08-23 00:12:38 +04:00
|
|
|
|
imageSize.width = nsPresContext::AppUnitsToIntCSSPixels(aFallbackSize.width);
|
2010-09-09 00:40:39 +04:00
|
|
|
|
}
|
|
|
|
|
if (!gotHeight) {
|
2014-08-23 00:12:38 +04:00
|
|
|
|
imageSize.height = nsPresContext::AppUnitsToIntCSSPixels(aFallbackSize.height);
|
2010-09-09 00:40:39 +04:00
|
|
|
|
}
|
2009-01-30 10:33:57 +03:00
|
|
|
|
|
2014-08-23 00:12:38 +04:00
|
|
|
|
return imageSize;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-05 00:50:56 +03:00
|
|
|
|
/* static */ DrawResult
|
2014-11-01 13:45:09 +03:00
|
|
|
|
nsLayoutUtils::DrawBackgroundImage(gfxContext& aContext,
|
2014-08-23 00:12:38 +04:00
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
|
imgIContainer* aImage,
|
2015-04-03 22:48:12 +03:00
|
|
|
|
const CSSIntSize& aImageSize,
|
2014-08-23 00:12:38 +04:00
|
|
|
|
GraphicsFilter aGraphicsFilter,
|
|
|
|
|
const nsRect& aDest,
|
|
|
|
|
const nsRect& aFill,
|
|
|
|
|
const nsPoint& aAnchor,
|
|
|
|
|
const nsRect& aDirty,
|
|
|
|
|
uint32_t aImageFlags)
|
|
|
|
|
{
|
|
|
|
|
PROFILER_LABEL("layout", "nsLayoutUtils::DrawBackgroundImage",
|
|
|
|
|
js::ProfileEntry::Category::GRAPHICS);
|
|
|
|
|
|
|
|
|
|
if (UseBackgroundNearestFiltering()) {
|
|
|
|
|
aGraphicsFilter = GraphicsFilter::FILTER_NEAREST;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SVGImageContext svgContext(aImageSize, Nothing());
|
|
|
|
|
|
2014-11-01 13:45:09 +03:00
|
|
|
|
return DrawImageInternal(aContext, aPresContext, aImage,
|
2014-08-23 00:12:38 +04:00
|
|
|
|
aGraphicsFilter, aDest, aFill, aAnchor,
|
|
|
|
|
aDirty, &svgContext, aImageFlags);
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-05 00:50:56 +03:00
|
|
|
|
/* static */ DrawResult
|
2014-11-01 13:45:09 +03:00
|
|
|
|
nsLayoutUtils::DrawImage(gfxContext& aContext,
|
2014-08-23 00:12:38 +04:00
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
|
imgIContainer* aImage,
|
|
|
|
|
GraphicsFilter aGraphicsFilter,
|
|
|
|
|
const nsRect& aDest,
|
|
|
|
|
const nsRect& aFill,
|
|
|
|
|
const nsPoint& aAnchor,
|
|
|
|
|
const nsRect& aDirty,
|
|
|
|
|
uint32_t aImageFlags)
|
|
|
|
|
{
|
2014-11-01 13:45:09 +03:00
|
|
|
|
return DrawImageInternal(aContext, aPresContext, aImage,
|
2014-08-23 00:12:38 +04:00
|
|
|
|
aGraphicsFilter, aDest, aFill, aAnchor,
|
|
|
|
|
aDirty, nullptr, aImageFlags);
|
2009-01-30 10:33:57 +03:00
|
|
|
|
}
|
|
|
|
|
|
2008-11-05 01:01:21 +03:00
|
|
|
|
/* static */ nsRect
|
2014-10-23 02:41:14 +04:00
|
|
|
|
nsLayoutUtils::GetWholeImageDestination(const nsSize& aWholeImageSize,
|
2008-11-05 01:01:21 +03:00
|
|
|
|
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);
|
2014-10-23 02:41:14 +04:00
|
|
|
|
nscoord wholeSizeX = NSToCoordRound(aWholeImageSize.width*scaleX);
|
|
|
|
|
nscoord wholeSizeY = NSToCoordRound(aWholeImageSize.height*scaleY);
|
2008-11-05 01:01:21 +03:00
|
|
|
|
return nsRect(aDestArea.TopLeft() - nsPoint(destOffsetX, destOffsetY),
|
|
|
|
|
nsSize(wholeSizeX, wholeSizeY));
|
2007-03-20 03:58:20 +03:00
|
|
|
|
}
|
2007-05-05 10:09:50 +04:00
|
|
|
|
|
2013-08-29 02:39:07 +04:00
|
|
|
|
/* static */ already_AddRefed<imgIContainer>
|
|
|
|
|
nsLayoutUtils::OrientImage(imgIContainer* aContainer,
|
|
|
|
|
const nsStyleImageOrientation& aOrientation)
|
|
|
|
|
{
|
|
|
|
|
MOZ_ASSERT(aContainer, "Should have an image container");
|
|
|
|
|
nsCOMPtr<imgIContainer> img(aContainer);
|
|
|
|
|
|
|
|
|
|
if (aOrientation.IsFromImage()) {
|
|
|
|
|
img = ImageOps::Orient(img, img->GetOrientation());
|
|
|
|
|
} else if (!aOrientation.IsDefault()) {
|
|
|
|
|
Angle angle = aOrientation.Angle();
|
|
|
|
|
Flip flip = aOrientation.IsFlipped() ? Flip::Horizontal
|
|
|
|
|
: Flip::Unflipped;
|
|
|
|
|
img = ImageOps::Orient(img, Orientation(angle, flip));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return img.forget();
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
|
static bool NonZeroStyleCoord(const nsStyleCoord& aCoord)
|
2007-05-10 19:46:42 +04:00
|
|
|
|
{
|
2010-09-09 19:21:45 +04: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 19:46:42 +04:00
|
|
|
|
}
|
2010-09-09 19:21:45 +04:00
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true;
|
2007-05-10 19:46:42 +04:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
|
/* static */ bool
|
2008-10-01 09:50:52 +04:00
|
|
|
|
nsLayoutUtils::HasNonZeroCorner(const nsStyleCorners& aCorners)
|
2007-05-10 19:46:42 +04:00
|
|
|
|
{
|
2008-10-01 09:50:52 +04:00
|
|
|
|
NS_FOR_CSS_HALF_CORNERS(corner) {
|
|
|
|
|
if (NonZeroStyleCoord(aCorners.Get(corner)))
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true;
|
2008-10-01 09:50:52 +04:00
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2007-05-10 19:46:42 +04:00
|
|
|
|
}
|
|
|
|
|
|
2009-05-08 05:52:22 +04:00
|
|
|
|
// aCorner is a "full corner" value, i.e. NS_CORNER_TOP_LEFT etc
|
2012-10-03 04:18:48 +04:00
|
|
|
|
static bool IsCornerAdjacentToSide(uint8_t aCorner, css::Side aSide)
|
2009-05-08 05:52:22 +04:00
|
|
|
|
{
|
2010-04-27 20:15:02 +04: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-08 05:52:22 +04:00
|
|
|
|
|
|
|
|
|
return aSide == aCorner || aSide == ((aCorner - 1)&3);
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
|
/* static */ bool
|
2009-05-08 05:52:22 +04:00
|
|
|
|
nsLayoutUtils::HasNonZeroCornerOnSide(const nsStyleCorners& aCorners,
|
2012-10-03 04:18:48 +04:00
|
|
|
|
css::Side aSide)
|
2009-05-08 05:52:22 +04: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 18:59:28 +04:00
|
|
|
|
return true;
|
2009-05-08 05:52:22 +04:00
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2009-05-08 05:52:22 +04:00
|
|
|
|
}
|
|
|
|
|
|
2008-08-13 04:44:14 +04:00
|
|
|
|
/* static */ nsTransparencyMode
|
2009-08-14 02:08:13 +04:00
|
|
|
|
nsLayoutUtils::GetFrameTransparency(nsIFrame* aBackgroundFrame,
|
|
|
|
|
nsIFrame* aCSSRootFrame) {
|
2013-02-17 01:51:02 +04:00
|
|
|
|
if (aCSSRootFrame->StyleDisplay()->mOpacity < 1.0f)
|
2008-08-13 04:44:14 +04:00
|
|
|
|
return eTransparencyTransparent;
|
2007-05-10 19:46:42 +04:00
|
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
|
if (HasNonZeroCorner(aCSSRootFrame->StyleBorder()->mBorderRadius))
|
2008-08-13 04:44:14 +04:00
|
|
|
|
return eTransparencyTransparent;
|
2007-05-10 19:46:42 +04:00
|
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
|
if (aCSSRootFrame->StyleDisplay()->mAppearance == NS_THEME_WIN_GLASS)
|
2008-08-13 04:44:14 +04:00
|
|
|
|
return eTransparencyGlass;
|
2009-02-05 06:05:48 +03:00
|
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
|
if (aCSSRootFrame->StyleDisplay()->mAppearance == NS_THEME_WIN_BORDERLESS_GLASS)
|
2010-08-18 07:07:10 +04:00
|
|
|
|
return eTransparencyBorderlessGlass;
|
|
|
|
|
|
2010-10-19 21:02:25 +04:00
|
|
|
|
nsITheme::Transparency transparency;
|
|
|
|
|
if (aCSSRootFrame->IsThemed(&transparency))
|
|
|
|
|
return transparency == nsITheme::eTransparent
|
|
|
|
|
? eTransparencyTransparent
|
|
|
|
|
: eTransparencyOpaque;
|
|
|
|
|
|
2009-02-05 06:05:48 +03: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-14 02:08:13 +04:00
|
|
|
|
if (aBackgroundFrame->GetType() == nsGkAtoms::viewportFrame &&
|
2011-08-25 00:54:30 +04:00
|
|
|
|
!aBackgroundFrame->GetFirstPrincipalChild()) {
|
2009-02-05 06:05:48 +03:00
|
|
|
|
return eTransparencyOpaque;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-03 05:58:26 +04:00
|
|
|
|
nsStyleContext* bgSC;
|
2013-03-07 20:03:49 +04:00
|
|
|
|
if (!nsCSSRendering::FindBackground(aBackgroundFrame, &bgSC)) {
|
2008-08-13 04:44:14 +04:00
|
|
|
|
return eTransparencyTransparent;
|
2009-08-14 02:08:13 +04:00
|
|
|
|
}
|
2013-02-17 01:51:02 +04:00
|
|
|
|
const nsStyleBackground* bg = bgSC->StyleBackground();
|
2009-02-20 08:29:21 +03: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-13 04:44:14 +04:00
|
|
|
|
return eTransparencyTransparent;
|
|
|
|
|
return eTransparencyOpaque;
|
2007-05-10 19:46:42 +04:00
|
|
|
|
}
|
2007-07-26 13:47:43 +04:00
|
|
|
|
|
2012-01-17 03:38:10 +04:00
|
|
|
|
static bool IsPopupFrame(nsIFrame* aFrame)
|
2010-01-12 00:45:18 +03:00
|
|
|
|
{
|
2012-01-17 03:38:10 +04:00
|
|
|
|
// aFrame is a popup it's the list control frame dropdown for a combobox.
|
2010-01-12 00:45:18 +03:00
|
|
|
|
nsIAtom* frameType = aFrame->GetType();
|
|
|
|
|
if (frameType == nsGkAtoms::listControlFrame) {
|
2012-01-17 03:38:10 +04:00
|
|
|
|
nsListControlFrame* lcf = static_cast<nsListControlFrame*>(aFrame);
|
|
|
|
|
return lcf->IsInDropDownMode();
|
2010-01-12 00:45:18 +03:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-17 03:38:10 +04: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-12 00:45:18 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* static */ nsIFrame*
|
|
|
|
|
nsLayoutUtils::GetDisplayRootFrame(nsIFrame* aFrame)
|
|
|
|
|
{
|
2012-08-29 09:39:01 +04:00
|
|
|
|
// We could use GetRootPresContext() here if the
|
|
|
|
|
// NS_FRAME_IN_POPUP frame bit is set.
|
2010-01-12 00:45:18 +03:00
|
|
|
|
nsIFrame* f = aFrame;
|
|
|
|
|
for (;;) {
|
2012-08-29 09:48:15 +04:00
|
|
|
|
if (!f->HasAnyStateBits(NS_FRAME_IN_POPUP)) {
|
|
|
|
|
f = f->PresContext()->FrameManager()->GetRootFrame();
|
|
|
|
|
} else if (IsPopup(f)) {
|
2010-01-12 00:45:18 +03:00
|
|
|
|
return f;
|
2012-08-29 09:48:15 +04:00
|
|
|
|
}
|
2010-01-12 00:45:18 +03:00
|
|
|
|
nsIFrame* parent = GetCrossDocParentFrame(f);
|
|
|
|
|
if (!parent)
|
|
|
|
|
return f;
|
|
|
|
|
f = parent;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-05 08:13:21 +04:00
|
|
|
|
/* static */ nsIFrame*
|
|
|
|
|
nsLayoutUtils::GetReferenceFrame(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
nsIFrame *f = aFrame;
|
|
|
|
|
for (;;) {
|
|
|
|
|
if (f->IsTransformed() || IsPopup(f)) {
|
|
|
|
|
return f;
|
|
|
|
|
}
|
|
|
|
|
nsIFrame* parent = GetCrossDocParentFrame(f);
|
|
|
|
|
if (!parent) {
|
|
|
|
|
return f;
|
|
|
|
|
}
|
|
|
|
|
f = parent;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-05 08:13:21 +04:00
|
|
|
|
/* static */ nsIFrame*
|
|
|
|
|
nsLayoutUtils::GetTransformRootFrame(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
nsIFrame *parent = nsLayoutUtils::GetCrossDocParentFrame(aFrame);
|
|
|
|
|
while (parent && parent->Preserves3DChildren()) {
|
|
|
|
|
parent = nsLayoutUtils::GetCrossDocParentFrame(parent);
|
|
|
|
|
}
|
|
|
|
|
return parent;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
/* static */ uint32_t
|
2007-07-26 13:47:43 +04:00
|
|
|
|
nsLayoutUtils::GetTextRunFlagsForStyle(nsStyleContext* aStyleContext,
|
2012-08-02 15:38:47 +04:00
|
|
|
|
const nsStyleFont* aStyleFont,
|
2014-02-05 14:16:23 +04:00
|
|
|
|
const nsStyleText* aStyleText,
|
2012-08-02 15:38:47 +04:00
|
|
|
|
nscoord aLetterSpacing)
|
2007-07-26 13:47:43 +04:00
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t result = 0;
|
2012-08-02 15:38:47 +04:00
|
|
|
|
if (aLetterSpacing != 0) {
|
2007-07-26 13:47:43 +04:00
|
|
|
|
result |= gfxTextRunFactory::TEXT_DISABLE_OPTIONAL_LIGATURES;
|
|
|
|
|
}
|
2014-02-05 14:16:23 +04:00
|
|
|
|
if (aStyleText->mControlCharacterVisibility == NS_STYLE_CONTROL_CHARACTER_VISIBILITY_HIDDEN) {
|
|
|
|
|
result |= gfxTextRunFactory::TEXT_HIDE_CONTROL_CHARACTERS;
|
|
|
|
|
}
|
2013-02-17 01:51:02 +04:00
|
|
|
|
switch (aStyleContext->StyleSVG()->mTextRendering) {
|
2007-07-26 13:47:43 +04:00
|
|
|
|
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;
|
|
|
|
|
}
|
2015-04-24 01:15:32 +03:00
|
|
|
|
return result | GetTextRunOrientFlagsForStyle(aStyleContext);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* static */ uint32_t
|
|
|
|
|
nsLayoutUtils::GetTextRunOrientFlagsForStyle(nsStyleContext* aStyleContext)
|
|
|
|
|
{
|
2014-11-13 11:58:04 +03:00
|
|
|
|
WritingMode wm(aStyleContext);
|
2014-09-16 15:25:45 +04:00
|
|
|
|
if (wm.IsVertical()) {
|
2014-12-11 21:56:19 +03:00
|
|
|
|
switch (aStyleContext->StyleVisibility()->mTextOrientation) {
|
2014-09-16 15:25:45 +04:00
|
|
|
|
case NS_STYLE_TEXT_ORIENTATION_MIXED:
|
2015-04-24 01:15:32 +03:00
|
|
|
|
return gfxTextRunFactory::TEXT_ORIENT_VERTICAL_MIXED;
|
2014-09-16 15:25:45 +04:00
|
|
|
|
case NS_STYLE_TEXT_ORIENTATION_UPRIGHT:
|
2015-04-24 01:15:32 +03:00
|
|
|
|
return gfxTextRunFactory::TEXT_ORIENT_VERTICAL_UPRIGHT;
|
2014-09-16 15:25:45 +04:00
|
|
|
|
case NS_STYLE_TEXT_ORIENTATION_SIDEWAYS:
|
|
|
|
|
// This should depend on writing mode vertical-lr vs vertical-rl,
|
|
|
|
|
// but until we support SIDEWAYS_LEFT, we'll treat this the same
|
|
|
|
|
// as SIDEWAYS_RIGHT and simply fall through.
|
|
|
|
|
/*
|
|
|
|
|
if (wm.IsVerticalLR()) {
|
2015-04-24 01:15:32 +03:00
|
|
|
|
return gfxTextRunFactory::TEXT_ORIENT_VERTICAL_SIDEWAYS_LEFT;
|
2014-09-16 15:25:45 +04:00
|
|
|
|
} else {
|
2015-04-24 01:15:32 +03:00
|
|
|
|
return gfxTextRunFactory::TEXT_ORIENT_VERTICAL_SIDEWAYS_RIGHT;
|
2014-09-16 15:25:45 +04:00
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
case NS_STYLE_TEXT_ORIENTATION_SIDEWAYS_RIGHT:
|
2015-04-24 01:15:32 +03:00
|
|
|
|
return gfxTextRunFactory::TEXT_ORIENT_VERTICAL_SIDEWAYS_RIGHT;
|
2014-09-16 15:25:45 +04:00
|
|
|
|
case NS_STYLE_TEXT_ORIENTATION_SIDEWAYS_LEFT:
|
|
|
|
|
// Not yet supported, so fall through to the default (error) case.
|
|
|
|
|
/*
|
2015-04-24 01:15:32 +03:00
|
|
|
|
return gfxTextRunFactory::TEXT_ORIENT_VERTICAL_SIDEWAYS_LEFT;
|
2014-09-16 15:25:45 +04:00
|
|
|
|
*/
|
|
|
|
|
default:
|
|
|
|
|
NS_NOTREACHED("unknown text-orientation");
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-04-24 01:15:32 +03:00
|
|
|
|
return 0;
|
2007-07-26 13:47:43 +04:00
|
|
|
|
}
|
2008-02-08 12:36:32 +03: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");
|
2013-01-15 16:22:03 +04:00
|
|
|
|
nsRect unionRect(aR1.x, aR1.y, std::max(aR1.width, aR2.width),
|
|
|
|
|
std::max(aR1.height, aR2.height));
|
|
|
|
|
nscoord VStripStart = std::min(aR1.width, aR2.width);
|
|
|
|
|
nscoord HStripStart = std::min(aR1.height, aR2.height);
|
2008-02-08 12:36:32 +03:00
|
|
|
|
*aVStrip = unionRect;
|
|
|
|
|
aVStrip->x += VStripStart;
|
|
|
|
|
aVStrip->width -= VStripStart;
|
|
|
|
|
*aHStrip = unionRect;
|
|
|
|
|
aHStrip->y += HStripStart;
|
|
|
|
|
aHStrip->height -= HStripStart;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-17 05:22:44 +04:00
|
|
|
|
nsDeviceContext*
|
2012-03-14 22:14:53 +04:00
|
|
|
|
nsLayoutUtils::GetDeviceContextForScreenInfo(nsPIDOMWindow* aWindow)
|
2008-07-26 20:14:49 +04:00
|
|
|
|
{
|
2012-04-16 13:33:35 +04:00
|
|
|
|
if (!aWindow) {
|
2012-07-30 18:20:58 +04:00
|
|
|
|
return nullptr;
|
2012-04-16 13:33:35 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-14 22:14:53 +04:00
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = aWindow->GetDocShell();
|
2008-07-26 20:14:49 +04: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.
|
2014-01-10 06:03:47 +04:00
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = docShell->GetWindow();
|
2008-07-26 20:14:49 +04:00
|
|
|
|
if (!win) {
|
|
|
|
|
// No reason to go on
|
2012-07-30 18:20:58 +04:00
|
|
|
|
return nullptr;
|
2008-07-26 20:14:49 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
win->EnsureSizeUpToDate();
|
|
|
|
|
|
2009-09-01 20:40:49 +04:00
|
|
|
|
nsRefPtr<nsPresContext> presContext;
|
|
|
|
|
docShell->GetPresContext(getter_AddRefs(presContext));
|
|
|
|
|
if (presContext) {
|
2011-04-17 05:22:44 +04:00
|
|
|
|
nsDeviceContext* context = presContext->DeviceContext();
|
2009-09-01 20:40:49 +04:00
|
|
|
|
if (context) {
|
|
|
|
|
return context;
|
|
|
|
|
}
|
2008-07-26 20:14:49 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentItem;
|
2013-02-13 02:02:51 +04:00
|
|
|
|
docShell->GetParent(getter_AddRefs(parentItem));
|
2008-07-26 20:14:49 +04:00
|
|
|
|
docShell = do_QueryInterface(parentItem);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
|
return nullptr;
|
2008-07-26 20:14:49 +04:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
|
/* static */ bool
|
2008-11-26 00:27:54 +03:00
|
|
|
|
nsLayoutUtils::IsReallyFixedPos(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
NS_PRECONDITION(aFrame->GetParent(),
|
|
|
|
|
"IsReallyFixedPos called on frame not in tree");
|
2013-02-17 01:51:02 +04:00
|
|
|
|
NS_PRECONDITION(aFrame->StyleDisplay()->mPosition ==
|
2008-11-26 00:27:54 +03:00
|
|
|
|
NS_STYLE_POSITION_FIXED,
|
|
|
|
|
"IsReallyFixedPos called on non-'position:fixed' frame");
|
|
|
|
|
|
2008-12-29 18:07:37 +03:00
|
|
|
|
nsIAtom *parentType = aFrame->GetParent()->GetType();
|
|
|
|
|
return parentType == nsGkAtoms::viewportFrame ||
|
|
|
|
|
parentType == nsGkAtoms::pageContentFrame;
|
2008-11-26 00:27:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-26 00:30:56 +04:00
|
|
|
|
nsLayoutUtils::SurfaceFromElementResult
|
2012-05-31 22:16:49 +04:00
|
|
|
|
nsLayoutUtils::SurfaceFromElement(nsIImageLoadingContent* aElement,
|
2013-12-12 01:05:27 +04:00
|
|
|
|
uint32_t aSurfaceFlags,
|
|
|
|
|
DrawTarget* aTarget)
|
2009-06-26 00:30:56 +04:00
|
|
|
|
{
|
|
|
|
|
SurfaceFromElementResult result;
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<imgIRequest> imgRequest;
|
2012-05-31 22:16:49 +04:00
|
|
|
|
rv = aElement->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
|
getter_AddRefs(imgRequest));
|
2009-06-26 00:30:56 +04:00
|
|
|
|
if (NS_FAILED(rv) || !imgRequest)
|
|
|
|
|
return result;
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t status;
|
2009-06-26 00:30:56 +04:00
|
|
|
|
imgRequest->GetImageStatus(&status);
|
2015-05-07 19:25:10 +03:00
|
|
|
|
result.mHasSize = status & imgIRequest::STATUS_SIZE_AVAILABLE;
|
2010-06-18 20:23:05 +04: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-26 00:30:56 +04:00
|
|
|
|
return result;
|
2010-06-18 20:23:05 +04:00
|
|
|
|
}
|
2009-06-26 00:30:56 +04:00
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
2011-09-21 01:00:42 +04:00
|
|
|
|
rv = imgRequest->GetImagePrincipal(getter_AddRefs(principal));
|
2012-10-17 03:05:54 +04:00
|
|
|
|
if (NS_FAILED(rv))
|
2011-09-21 01:00:42 +04:00
|
|
|
|
return result;
|
2009-06-26 00:30:56 +04: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-21 05:50:15 +04:00
|
|
|
|
nsCOMPtr<imgIContainer> imgContainer;
|
2009-06-26 00:30:56 +04:00
|
|
|
|
rv = imgRequest->GetImage(getter_AddRefs(imgContainer));
|
2012-10-17 03:05:54 +04:00
|
|
|
|
if (NS_FAILED(rv))
|
2009-06-26 00:30:56 +04:00
|
|
|
|
return result;
|
|
|
|
|
|
2014-01-13 04:29:48 +04:00
|
|
|
|
uint32_t noRasterize = aSurfaceFlags & SFE_NO_RASTERIZING_VECTORS;
|
|
|
|
|
|
2012-08-22 19:56:38 +04: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-13 04:45:13 +03:00
|
|
|
|
if (aSurfaceFlags & SFE_NO_COLORSPACE_CONVERSION)
|
|
|
|
|
frameFlags |= imgIContainer::FLAG_DECODE_NO_COLORSPACE_CONVERSION;
|
2014-04-17 09:29:52 +04:00
|
|
|
|
if (aSurfaceFlags & SFE_PREFER_NO_PREMULTIPLY_ALPHA) {
|
2011-01-13 04:45:13 +03:00
|
|
|
|
frameFlags |= imgIContainer::FLAG_DECODE_NO_PREMULTIPLY_ALPHA;
|
2014-04-17 09:29:52 +04:00
|
|
|
|
result.mIsPremultiplied = false;
|
|
|
|
|
}
|
2009-06-26 00:30:56 +04:00
|
|
|
|
|
2012-08-22 19:56:38 +04: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-21 05:50:15 +04:00
|
|
|
|
rv = imgContainer->GetWidth(&imgWidth);
|
2012-07-27 18:03:08 +04:00
|
|
|
|
nsresult rv2 = imgContainer->GetHeight(&imgHeight);
|
|
|
|
|
if (NS_FAILED(rv) || NS_FAILED(rv2))
|
2009-06-26 00:30:56 +04:00
|
|
|
|
return result;
|
|
|
|
|
|
2014-01-13 04:29:48 +04:00
|
|
|
|
if (!noRasterize || imgContainer->GetType() == imgIContainer::TYPE_RASTER) {
|
2014-04-15 22:02:23 +04:00
|
|
|
|
if (aSurfaceFlags & SFE_WANT_IMAGE_SURFACE) {
|
|
|
|
|
frameFlags |= imgIContainer::FLAG_WANT_DATA_SURFACE;
|
2014-04-15 06:36:27 +04:00
|
|
|
|
}
|
2014-04-15 22:02:23 +04:00
|
|
|
|
result.mSourceSurface = imgContainer->GetFrame(whichFrame, frameFlags);
|
2014-04-15 06:36:27 +04:00
|
|
|
|
if (!result.mSourceSurface) {
|
2014-04-15 22:02:23 +04:00
|
|
|
|
return result;
|
2014-01-13 04:29:48 +04:00
|
|
|
|
}
|
2014-04-16 04:40:18 +04:00
|
|
|
|
// The surface we return is likely to be cached. We don't want to have to
|
|
|
|
|
// convert to a surface that's compatible with aTarget each time it's used
|
|
|
|
|
// (that would result in terrible performance), so we convert once here
|
|
|
|
|
// upfront if aTarget is specified.
|
|
|
|
|
if (aTarget) {
|
|
|
|
|
RefPtr<SourceSurface> optSurface =
|
|
|
|
|
aTarget->OptimizeSourceSurface(result.mSourceSurface);
|
|
|
|
|
if (optSurface) {
|
|
|
|
|
result.mSourceSurface = optSurface;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-12 01:05:27 +04:00
|
|
|
|
} else {
|
2014-01-13 04:29:48 +04:00
|
|
|
|
result.mDrawInfo.mImgContainer = imgContainer;
|
|
|
|
|
result.mDrawInfo.mWhichFrame = whichFrame;
|
|
|
|
|
result.mDrawInfo.mDrawingFlags = frameFlags;
|
2009-06-26 00:30:56 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t corsmode;
|
2011-09-10 01:58:35 +04:00
|
|
|
|
if (NS_SUCCEEDED(imgRequest->GetCORSMode(&corsmode))) {
|
|
|
|
|
result.mCORSUsed = (corsmode != imgIRequest::CORS_NONE);
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-26 00:30:56 +04:00
|
|
|
|
result.mSize = gfxIntSize(imgWidth, imgHeight);
|
2011-03-24 06:13:56 +03:00
|
|
|
|
result.mPrincipal = principal.forget();
|
2011-12-19 01:57:41 +04:00
|
|
|
|
// no images, including SVG images, can load content from another domain.
|
|
|
|
|
result.mIsWriteOnly = false;
|
2011-03-24 06:13:56 +03:00
|
|
|
|
result.mImageRequest = imgRequest.forget();
|
2009-06-26 00:30:56 +04:00
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-31 22:16:49 +04:00
|
|
|
|
nsLayoutUtils::SurfaceFromElementResult
|
2012-12-31 21:25:46 +04:00
|
|
|
|
nsLayoutUtils::SurfaceFromElement(HTMLImageElement *aElement,
|
2013-12-12 01:05:27 +04:00
|
|
|
|
uint32_t aSurfaceFlags,
|
|
|
|
|
DrawTarget* aTarget)
|
2012-05-31 22:16:49 +04:00
|
|
|
|
{
|
|
|
|
|
return SurfaceFromElement(static_cast<nsIImageLoadingContent*>(aElement),
|
2013-12-12 01:05:27 +04:00
|
|
|
|
aSurfaceFlags, aTarget);
|
2012-05-31 22:16:49 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsLayoutUtils::SurfaceFromElementResult
|
2013-01-04 09:16:14 +04:00
|
|
|
|
nsLayoutUtils::SurfaceFromElement(HTMLCanvasElement* aElement,
|
2013-12-12 01:05:27 +04:00
|
|
|
|
uint32_t aSurfaceFlags,
|
|
|
|
|
DrawTarget* aTarget)
|
2012-05-31 22:16:49 +04:00
|
|
|
|
{
|
|
|
|
|
SurfaceFromElementResult result;
|
|
|
|
|
|
2014-04-17 09:29:52 +04:00
|
|
|
|
bool* isPremultiplied = nullptr;
|
|
|
|
|
if (aSurfaceFlags & SFE_PREFER_NO_PREMULTIPLY_ALPHA) {
|
|
|
|
|
isPremultiplied = &result.mIsPremultiplied;
|
|
|
|
|
}
|
2012-05-31 22:16:49 +04:00
|
|
|
|
|
|
|
|
|
gfxIntSize size = aElement->GetSize();
|
|
|
|
|
|
2014-04-17 09:29:52 +04:00
|
|
|
|
result.mSourceSurface = aElement->GetSurfaceSnapshot(isPremultiplied);
|
2013-12-12 01:05:27 +04:00
|
|
|
|
if (!result.mSourceSurface) {
|
2014-04-17 09:29:52 +04:00
|
|
|
|
// If the element doesn't have a context then we won't get a snapshot. The canvas spec wants us to not error and just
|
|
|
|
|
// draw nothing, so return an empty surface.
|
|
|
|
|
DrawTarget *ref = aTarget ? aTarget : gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget();
|
|
|
|
|
RefPtr<DrawTarget> dt = ref->CreateSimilarDrawTarget(IntSize(size.width, size.height),
|
|
|
|
|
SurfaceFormat::B8G8R8A8);
|
|
|
|
|
if (dt) {
|
|
|
|
|
result.mSourceSurface = dt->Snapshot();
|
|
|
|
|
}
|
|
|
|
|
} else if (aTarget) {
|
|
|
|
|
RefPtr<SourceSurface> opt = aTarget->OptimizeSourceSurface(result.mSourceSurface);
|
|
|
|
|
if (opt) {
|
|
|
|
|
result.mSourceSurface = opt;
|
2013-12-12 01:05:27 +04:00
|
|
|
|
}
|
2012-05-31 22:16:49 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ensure that any future changes to the canvas trigger proper invalidation,
|
|
|
|
|
// in case this is being used by -moz-element()
|
|
|
|
|
aElement->MarkContextClean();
|
|
|
|
|
|
2015-05-07 19:25:10 +03:00
|
|
|
|
result.mHasSize = true;
|
2012-05-31 22:16:49 +04:00
|
|
|
|
result.mSize = size;
|
|
|
|
|
result.mPrincipal = aElement->NodePrincipal();
|
|
|
|
|
result.mIsWriteOnly = aElement->IsWriteOnly();
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsLayoutUtils::SurfaceFromElementResult
|
2013-03-19 16:27:35 +04:00
|
|
|
|
nsLayoutUtils::SurfaceFromElement(HTMLVideoElement* aElement,
|
2013-12-12 01:05:27 +04:00
|
|
|
|
uint32_t aSurfaceFlags,
|
|
|
|
|
DrawTarget* aTarget)
|
2012-05-31 22:16:49 +04:00
|
|
|
|
{
|
|
|
|
|
SurfaceFromElementResult result;
|
|
|
|
|
|
2014-04-17 09:29:52 +04:00
|
|
|
|
NS_WARN_IF_FALSE((aSurfaceFlags & SFE_PREFER_NO_PREMULTIPLY_ALPHA) == 0, "We can't support non-premultiplied alpha for video!");
|
2012-05-31 22:16:49 +04:00
|
|
|
|
|
2014-10-28 03:21:12 +03:00
|
|
|
|
#ifdef MOZ_EME
|
|
|
|
|
if (aElement->ContainsRestrictedContent()) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint16_t readyState;
|
2012-05-31 22:16:49 +04: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;
|
|
|
|
|
|
2015-03-27 02:07:53 +03:00
|
|
|
|
AutoLockImage lockImage(container);
|
|
|
|
|
layers::Image* image = lockImage.GetImage();
|
|
|
|
|
if (!image) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
result.mSourceSurface = image->GetAsSourceSurface();
|
2014-04-02 15:32:24 +04:00
|
|
|
|
if (!result.mSourceSurface)
|
2012-05-31 22:16:49 +04:00
|
|
|
|
return result;
|
|
|
|
|
|
2014-04-17 09:29:52 +04:00
|
|
|
|
if (aTarget) {
|
|
|
|
|
RefPtr<SourceSurface> opt = aTarget->OptimizeSourceSurface(result.mSourceSurface);
|
|
|
|
|
if (opt) {
|
|
|
|
|
result.mSourceSurface = opt;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-31 22:16:49 +04:00
|
|
|
|
result.mCORSUsed = aElement->GetCORSMode() != CORS_NONE;
|
2015-05-07 19:25:10 +03:00
|
|
|
|
result.mHasSize = true;
|
2015-03-27 02:07:53 +03:00
|
|
|
|
result.mSize = image->GetSize();
|
2012-05-31 22:16:49 +04:00
|
|
|
|
result.mPrincipal = principal.forget();
|
|
|
|
|
result.mIsWriteOnly = false;
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsLayoutUtils::SurfaceFromElementResult
|
|
|
|
|
nsLayoutUtils::SurfaceFromElement(dom::Element* aElement,
|
2013-12-12 01:05:27 +04:00
|
|
|
|
uint32_t aSurfaceFlags,
|
|
|
|
|
DrawTarget* aTarget)
|
2012-05-31 22:16:49 +04:00
|
|
|
|
{
|
|
|
|
|
// If it's a <canvas>, we may be able to just grab its internal surface
|
2013-01-04 09:16:14 +04:00
|
|
|
|
if (HTMLCanvasElement* canvas =
|
|
|
|
|
HTMLCanvasElement::FromContentOrNull(aElement)) {
|
2013-12-12 01:05:27 +04:00
|
|
|
|
return SurfaceFromElement(canvas, aSurfaceFlags, aTarget);
|
2012-05-31 22:16:49 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Maybe it's <video>?
|
2013-03-19 16:27:35 +04:00
|
|
|
|
if (HTMLVideoElement* video =
|
|
|
|
|
HTMLVideoElement::FromContentOrNull(aElement)) {
|
2013-12-12 01:05:27 +04:00
|
|
|
|
return SurfaceFromElement(video, aSurfaceFlags, aTarget);
|
2012-05-31 22:16:49 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Finally, check if it's a normal image
|
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(aElement);
|
|
|
|
|
|
|
|
|
|
if (!imageLoader) {
|
|
|
|
|
return SurfaceFromElementResult();
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-12 01:05:27 +04:00
|
|
|
|
return SurfaceFromElement(imageLoader, aSurfaceFlags, aTarget);
|
2012-05-31 22:16:49 +04:00
|
|
|
|
}
|
|
|
|
|
|
2010-04-21 17:13:08 +04:00
|
|
|
|
/* static */
|
|
|
|
|
nsIContent*
|
|
|
|
|
nsLayoutUtils::GetEditableRootContentByContentEditable(nsIDocument* aDocument)
|
|
|
|
|
{
|
2013-10-08 22:47:21 +04:00
|
|
|
|
// If the document is in designMode we should return nullptr.
|
2010-04-21 17:13:08 +04:00
|
|
|
|
if (!aDocument || aDocument->HasFlag(NODE_IS_EDITABLE)) {
|
2012-07-30 18:20:58 +04:00
|
|
|
|
return nullptr;
|
2010-04-21 17:13:08 +04: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 18:20:58 +04:00
|
|
|
|
return nullptr;
|
2010-04-21 17:13:08 +04:00
|
|
|
|
}
|
|
|
|
|
|
2010-04-30 17:12:05 +04:00
|
|
|
|
Element* rootElement = aDocument->GetRootElement();
|
|
|
|
|
if (rootElement && rootElement->IsEditable()) {
|
|
|
|
|
return rootElement;
|
2010-04-21 17:13:08 +04: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 18:20:58 +04:00
|
|
|
|
return nullptr;
|
2010-04-21 17:13:08 +04:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-12 04:09:21 +03:00
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
/* static */ void
|
|
|
|
|
nsLayoutUtils::AssertNoDuplicateContinuations(nsIFrame* aContainer,
|
|
|
|
|
const nsFrameList& aFrameList)
|
|
|
|
|
{
|
2015-06-29 23:02:21 +03:00
|
|
|
|
for (nsIFrame* f : aFrameList) {
|
2011-01-12 04:09:21 +03:00
|
|
|
|
// 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-12 04:09:22 +03: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 19:56:38 +04:00
|
|
|
|
int32_t start, end;
|
2011-01-12 04:09:22 +03: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-25 00:54:29 +04: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-12 04:09:22 +03:00
|
|
|
|
}
|
2011-08-25 00:54:29 +04:00
|
|
|
|
}
|
2011-01-12 04:09:22 +03:00
|
|
|
|
}
|
2011-01-12 04:09:21 +03:00
|
|
|
|
#endif
|
|
|
|
|
|
2013-12-18 17:25:54 +04:00
|
|
|
|
static void
|
|
|
|
|
GetFontFacesForFramesInner(nsIFrame* aFrame, nsFontFaceList* aFontFaceList)
|
|
|
|
|
{
|
|
|
|
|
NS_PRECONDITION(aFrame, "NULL frame pointer");
|
|
|
|
|
|
|
|
|
|
if (aFrame->GetType() == nsGkAtoms::textFrame) {
|
2013-12-18 17:25:54 +04:00
|
|
|
|
if (!aFrame->GetPrevContinuation()) {
|
|
|
|
|
nsLayoutUtils::GetFontFacesForText(aFrame, 0, INT32_MAX, true,
|
|
|
|
|
aFontFaceList);
|
|
|
|
|
}
|
2013-12-18 17:25:54 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIFrame::ChildListID childLists[] = { nsIFrame::kPrincipalList,
|
|
|
|
|
nsIFrame::kPopupList };
|
|
|
|
|
for (size_t i = 0; i < ArrayLength(childLists); ++i) {
|
|
|
|
|
nsFrameList children(aFrame->GetChildList(childLists[i]));
|
|
|
|
|
for (nsFrameList::Enumerator e(children); !e.AtEnd(); e.Next()) {
|
|
|
|
|
nsIFrame* child = e.get();
|
|
|
|
|
child = nsPlaceholderFrame::GetRealFrameFor(child);
|
|
|
|
|
GetFontFacesForFramesInner(child, aFontFaceList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-16 10:31:36 +04:00
|
|
|
|
/* static */
|
|
|
|
|
nsresult
|
|
|
|
|
nsLayoutUtils::GetFontFacesForFrames(nsIFrame* aFrame,
|
|
|
|
|
nsFontFaceList* aFontFaceList)
|
|
|
|
|
{
|
|
|
|
|
NS_PRECONDITION(aFrame, "NULL frame pointer");
|
|
|
|
|
|
|
|
|
|
while (aFrame) {
|
2013-12-18 17:25:54 +04:00
|
|
|
|
GetFontFacesForFramesInner(aFrame, aFontFaceList);
|
2014-02-07 05:45:31 +04:00
|
|
|
|
aFrame = GetNextContinuationOrIBSplitSibling(aFrame);
|
2011-06-16 10:31:36 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
|
nsresult
|
|
|
|
|
nsLayoutUtils::GetFontFacesForText(nsIFrame* aFrame,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t aStartOffset, int32_t aEndOffset,
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool aFollowContinuations,
|
2011-06-16 10:31:36 +04:00
|
|
|
|
nsFontFaceList* aFontFaceList)
|
|
|
|
|
{
|
|
|
|
|
NS_PRECONDITION(aFrame, "NULL frame pointer");
|
|
|
|
|
|
|
|
|
|
if (aFrame->GetType() != nsGkAtoms::textFrame) {
|
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsTextFrame* curr = static_cast<nsTextFrame*>(aFrame);
|
|
|
|
|
do {
|
2013-01-15 16:22:03 +04:00
|
|
|
|
int32_t fstart = std::max(curr->GetContentOffset(), aStartOffset);
|
|
|
|
|
int32_t fend = std::min(curr->GetContentEnd(), aEndOffset);
|
2011-06-16 10:31:36 +04:00
|
|
|
|
if (fstart >= fend) {
|
2013-12-18 17:25:54 +04:00
|
|
|
|
curr = static_cast<nsTextFrame*>(curr->GetNextContinuation());
|
2011-06-16 10:31:36 +04:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-18 17:25:54 +04:00
|
|
|
|
// curr is overlapping with the offset we want
|
2011-11-24 06:48:23 +04:00
|
|
|
|
gfxSkipCharsIterator iter = curr->EnsureTextRun(nsTextFrame::eInflated);
|
|
|
|
|
gfxTextRun* textRun = curr->GetTextRun(nsTextFrame::eInflated);
|
2011-06-16 10:31:36 +04:00
|
|
|
|
NS_ENSURE_TRUE(textRun, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
2013-12-18 17:25:54 +04:00
|
|
|
|
// include continuations in the range that share the same textrun
|
|
|
|
|
nsTextFrame* next = nullptr;
|
|
|
|
|
if (aFollowContinuations && fend < aEndOffset) {
|
|
|
|
|
next = static_cast<nsTextFrame*>(curr->GetNextContinuation());
|
|
|
|
|
while (next && next->GetTextRun(nsTextFrame::eInflated) == textRun) {
|
|
|
|
|
fend = std::min(next->GetContentEnd(), aEndOffset);
|
|
|
|
|
next = fend < aEndOffset ?
|
|
|
|
|
static_cast<nsTextFrame*>(next->GetNextContinuation()) : nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t skipStart = iter.ConvertOriginalToSkipped(fstart);
|
|
|
|
|
uint32_t skipEnd = iter.ConvertOriginalToSkipped(fend);
|
2013-12-18 17:25:54 +04:00
|
|
|
|
aFontFaceList->AddFontsFromTextRun(textRun, skipStart, skipEnd - skipStart);
|
2013-12-18 17:25:54 +04:00
|
|
|
|
curr = next;
|
|
|
|
|
} while (aFollowContinuations && curr);
|
2011-06-16 10:31:36 +04:00
|
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-14 11:06:35 +04:00
|
|
|
|
/* static */
|
2011-11-28 07:03:14 +04:00
|
|
|
|
size_t
|
|
|
|
|
nsLayoutUtils::SizeOfTextRunsForFrames(nsIFrame* aFrame,
|
2013-06-23 16:03:39 +04:00
|
|
|
|
MallocSizeOf aMallocSizeOf,
|
2011-11-28 07:03:14 +04:00
|
|
|
|
bool clear)
|
2011-10-14 11:06:35 +04:00
|
|
|
|
{
|
|
|
|
|
NS_PRECONDITION(aFrame, "NULL frame pointer");
|
|
|
|
|
|
2011-11-28 07:03:14 +04:00
|
|
|
|
size_t total = 0;
|
|
|
|
|
|
2011-10-14 11:06:35 +04:00
|
|
|
|
if (aFrame->GetType() == nsGkAtoms::textFrame) {
|
|
|
|
|
nsTextFrame* textFrame = static_cast<nsTextFrame*>(aFrame);
|
2012-08-22 19:56:38 +04:00
|
|
|
|
for (uint32_t i = 0; i < 2; ++i) {
|
2011-11-24 06:48:23 +04:00
|
|
|
|
gfxTextRun *run = textFrame->GetTextRun(
|
|
|
|
|
(i != 0) ? nsTextFrame::eInflated : nsTextFrame::eNotInflated);
|
|
|
|
|
if (run) {
|
2011-11-28 07:03:14 +04:00
|
|
|
|
if (clear) {
|
|
|
|
|
run->ResetSizeOfAccountingFlags();
|
2011-11-24 06:48:23 +04:00
|
|
|
|
} else {
|
2011-11-28 07:03:14 +04:00
|
|
|
|
total += run->MaybeSizeOfIncludingThis(aMallocSizeOf);
|
2011-11-24 06:48:23 +04:00
|
|
|
|
}
|
2011-10-14 11:06:35 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-11-28 07:03:14 +04:00
|
|
|
|
return total;
|
2011-10-14 11:06:35 +04: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-28 07:03:14 +04:00
|
|
|
|
total += SizeOfTextRunsForFrames(e.get(), aMallocSizeOf, clear);
|
2011-10-14 11:06:35 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-11-28 07:03:14 +04:00
|
|
|
|
return total;
|
2011-10-14 11:06:35 +04:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-24 06:48:23 +04:00
|
|
|
|
/* static */
|
|
|
|
|
void
|
|
|
|
|
nsLayoutUtils::Initialize()
|
|
|
|
|
{
|
2012-10-15 23:03:37 +04:00
|
|
|
|
Preferences::AddUintVarCache(&sFontSizeInflationMaxRatio,
|
|
|
|
|
"font.size.inflation.maxRatio");
|
2012-10-03 04:18:48 +04:00
|
|
|
|
Preferences::AddUintVarCache(&sFontSizeInflationEmPerLine,
|
|
|
|
|
"font.size.inflation.emPerLine");
|
|
|
|
|
Preferences::AddUintVarCache(&sFontSizeInflationMinTwips,
|
|
|
|
|
"font.size.inflation.minTwips");
|
|
|
|
|
Preferences::AddUintVarCache(&sFontSizeInflationLineThreshold,
|
|
|
|
|
"font.size.inflation.lineThreshold");
|
|
|
|
|
Preferences::AddIntVarCache(&sFontSizeInflationMappingIntercept,
|
|
|
|
|
"font.size.inflation.mappingIntercept");
|
2012-11-20 23:55:14 +04:00
|
|
|
|
Preferences::AddBoolVarCache(&sFontSizeInflationForceEnabled,
|
|
|
|
|
"font.size.inflation.forceEnabled");
|
2012-11-29 00:16:01 +04:00
|
|
|
|
Preferences::AddBoolVarCache(&sFontSizeInflationDisabledInMasterProcess,
|
|
|
|
|
"font.size.inflation.disabledInMasterProcess");
|
2013-05-14 03:47:02 +04:00
|
|
|
|
Preferences::AddBoolVarCache(&sInvalidationDebuggingIsEnabled,
|
|
|
|
|
"nglayout.debug.invalidation");
|
2013-12-12 06:09:40 +04:00
|
|
|
|
Preferences::AddBoolVarCache(&sCSSVariablesEnabled,
|
|
|
|
|
"layout.css.variables.enabled");
|
2014-04-10 08:47:58 +04:00
|
|
|
|
Preferences::AddBoolVarCache(&sInterruptibleReflowEnabled,
|
|
|
|
|
"layout.interruptible-reflow.enabled");
|
2015-05-25 00:40:37 +03:00
|
|
|
|
Preferences::AddBoolVarCache(&sSVGTransformOriginEnabled,
|
|
|
|
|
"svg.transform-origin.enabled");
|
2012-10-03 09:04:50 +04:00
|
|
|
|
|
2014-02-27 11:45:29 +04:00
|
|
|
|
Preferences::RegisterCallback(GridEnabledPrefChangeCallback,
|
|
|
|
|
GRID_ENABLED_PREF_NAME);
|
|
|
|
|
GridEnabledPrefChangeCallback(GRID_ENABLED_PREF_NAME, nullptr);
|
2014-07-23 06:08:01 +04:00
|
|
|
|
Preferences::RegisterCallback(RubyEnabledPrefChangeCallback,
|
|
|
|
|
RUBY_ENABLED_PREF_NAME);
|
|
|
|
|
RubyEnabledPrefChangeCallback(RUBY_ENABLED_PREF_NAME, nullptr);
|
2013-09-06 02:47:08 +04:00
|
|
|
|
Preferences::RegisterCallback(StickyEnabledPrefChangeCallback,
|
|
|
|
|
STICKY_ENABLED_PREF_NAME);
|
|
|
|
|
StickyEnabledPrefChangeCallback(STICKY_ENABLED_PREF_NAME, nullptr);
|
2013-10-28 00:56:32 +04:00
|
|
|
|
Preferences::RegisterCallback(TextAlignTrueEnabledPrefChangeCallback,
|
|
|
|
|
TEXT_ALIGN_TRUE_ENABLED_PREF_NAME);
|
2014-11-20 21:24:09 +03:00
|
|
|
|
Preferences::RegisterCallback(DisplayContentsEnabledPrefChangeCallback,
|
|
|
|
|
DISPLAY_CONTENTS_ENABLED_PREF_NAME);
|
|
|
|
|
DisplayContentsEnabledPrefChangeCallback(DISPLAY_CONTENTS_ENABLED_PREF_NAME,
|
|
|
|
|
nullptr);
|
2013-10-28 00:56:32 +04:00
|
|
|
|
TextAlignTrueEnabledPrefChangeCallback(TEXT_ALIGN_TRUE_ENABLED_PREF_NAME,
|
|
|
|
|
nullptr);
|
2013-10-03 14:58:01 +04:00
|
|
|
|
|
|
|
|
|
nsComputedDOMStyle::RegisterPrefChangeCallbacks();
|
2011-11-24 06:48:23 +04:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-13 20:45:14 +03:00
|
|
|
|
/* static */
|
|
|
|
|
void
|
|
|
|
|
nsLayoutUtils::Shutdown()
|
|
|
|
|
{
|
|
|
|
|
if (sContentMap) {
|
|
|
|
|
delete sContentMap;
|
2012-10-03 04:18:48 +04:00
|
|
|
|
sContentMap = nullptr;
|
2011-01-13 20:45:14 +03:00
|
|
|
|
}
|
2012-10-03 09:04:50 +04:00
|
|
|
|
|
2014-02-27 11:45:29 +04:00
|
|
|
|
Preferences::UnregisterCallback(GridEnabledPrefChangeCallback,
|
|
|
|
|
GRID_ENABLED_PREF_NAME);
|
2014-07-23 06:08:01 +04:00
|
|
|
|
Preferences::UnregisterCallback(RubyEnabledPrefChangeCallback,
|
|
|
|
|
RUBY_ENABLED_PREF_NAME);
|
2013-09-06 02:47:08 +04:00
|
|
|
|
Preferences::UnregisterCallback(StickyEnabledPrefChangeCallback,
|
|
|
|
|
STICKY_ENABLED_PREF_NAME);
|
2013-10-03 14:58:01 +04:00
|
|
|
|
|
|
|
|
|
nsComputedDOMStyle::UnregisterPrefChangeCallbacks();
|
2011-01-13 20:45:14 +03:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-10 01:39:16 +04: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;
|
2012-10-17 03:05:54 +04:00
|
|
|
|
if (NS_SUCCEEDED(aRequest->GetImage(getter_AddRefs(image)))) {
|
2011-11-10 01:39:16 +04:00
|
|
|
|
// 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;
|
2012-10-17 03:05:54 +04:00
|
|
|
|
if (NS_SUCCEEDED(aRequest->GetImage(getter_AddRefs(image)))) {
|
2011-11-10 01:39:16 +04:00
|
|
|
|
aPresContext->RefreshDriver()->RemoveImageRequest(aRequest);
|
|
|
|
|
|
|
|
|
|
if (aRequestRegistered) {
|
|
|
|
|
*aRequestRegistered = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-17 08:05:09 +04:00
|
|
|
|
/* static */
|
|
|
|
|
void
|
|
|
|
|
nsLayoutUtils::PostRestyleEvent(Element* aElement,
|
|
|
|
|
nsRestyleHint aRestyleHint,
|
|
|
|
|
nsChangeHint aMinChangeHint)
|
|
|
|
|
{
|
2014-08-06 03:23:02 +04:00
|
|
|
|
nsIDocument* doc = aElement->GetComposedDoc();
|
2012-05-17 08:05:09 +04:00
|
|
|
|
if (doc) {
|
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = doc->GetShell();
|
|
|
|
|
if (presShell) {
|
2013-07-20 23:14:25 +04:00
|
|
|
|
presShell->GetPresContext()->RestyleManager()->PostRestyleEvent(
|
2012-05-17 08:05:09 +04:00
|
|
|
|
aElement, aRestyleHint, aMinChangeHint);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-15 03:59:21 +04: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 17:23:36 +04:00
|
|
|
|
nsSetAttrRunnable::nsSetAttrRunnable(nsIContent* aContent, nsIAtom* aAttrName,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t aValue)
|
2010-05-03 17:23:36 +04:00
|
|
|
|
: mContent(aContent),
|
|
|
|
|
mAttrName(aAttrName)
|
|
|
|
|
{
|
|
|
|
|
NS_ASSERTION(aContent && aAttrName, "Missing stuff, prepare to crash");
|
|
|
|
|
mValue.AppendInt(aValue);
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-15 03:59:21 +04:00
|
|
|
|
NS_IMETHODIMP
|
|
|
|
|
nsSetAttrRunnable::Run()
|
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return mContent->SetAttr(kNameSpaceID_None, mAttrName, mValue, true);
|
2008-04-15 03:59:21 +04: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 18:59:28 +04:00
|
|
|
|
return mContent->UnsetAttr(kNameSpaceID_None, mAttrName, true);
|
2008-04-15 03:59:21 +04:00
|
|
|
|
}
|
2009-01-19 12:29:48 +03:00
|
|
|
|
|
2011-11-24 06:48:23 +04: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
|
2015-03-10 17:28:23 +03:00
|
|
|
|
MinimumFontSizeFor(nsPresContext* aPresContext, WritingMode aWritingMode,
|
|
|
|
|
nscoord aContainerISize)
|
2011-11-24 06:48:23 +04:00
|
|
|
|
{
|
2012-06-06 07:47:33 +04:00
|
|
|
|
nsIPresShell* presShell = aPresContext->PresShell();
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t emPerLine = presShell->FontSizeInflationEmPerLine();
|
|
|
|
|
uint32_t minTwips = presShell->FontSizeInflationMinTwips();
|
2012-05-05 17:28:06 +04:00
|
|
|
|
if (emPerLine == 0 && minTwips == 0) {
|
2011-11-24 06:48:23 +04:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2011-12-21 02:34:54 +04:00
|
|
|
|
|
|
|
|
|
// Clamp the container width to the device dimensions
|
2015-03-10 17:28:23 +03:00
|
|
|
|
nscoord iFrameISize = aWritingMode.IsVertical()
|
|
|
|
|
? aPresContext->GetVisibleArea().height
|
|
|
|
|
: aPresContext->GetVisibleArea().width;
|
|
|
|
|
nscoord effectiveContainerISize = std::min(iFrameISize, aContainerISize);
|
2011-12-21 02:34:54 +04:00
|
|
|
|
|
2011-11-24 06:48:23 +04:00
|
|
|
|
nscoord byLine = 0, byInch = 0;
|
2012-05-05 17:28:06 +04:00
|
|
|
|
if (emPerLine != 0) {
|
2015-03-10 17:28:23 +03:00
|
|
|
|
byLine = effectiveContainerISize / emPerLine;
|
2011-11-24 06:48:23 +04:00
|
|
|
|
}
|
2012-05-05 17:28:06 +04:00
|
|
|
|
if (minTwips != 0) {
|
2011-11-24 06:48:23 +04:00
|
|
|
|
// REVIEW: Is this giving us app units and sizes *not* counting
|
|
|
|
|
// viewport scaling?
|
2015-03-10 17:28:23 +03:00
|
|
|
|
gfxSize screenSize = aPresContext->ScreenSizeInchesForFontInflation();
|
|
|
|
|
float deviceISizeInches = aWritingMode.IsVertical()
|
|
|
|
|
? screenSize.height : screenSize.width;
|
|
|
|
|
byInch = NSToCoordRound(effectiveContainerISize /
|
|
|
|
|
(deviceISizeInches * 1440 /
|
2012-05-05 17:28:06 +04:00
|
|
|
|
minTwips ));
|
2011-11-24 06:48:23 +04:00
|
|
|
|
}
|
2013-01-15 16:22:03 +04:00
|
|
|
|
return std::max(byLine, byInch);
|
2011-11-24 06:48:23 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 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.
|
2013-02-17 01:51:02 +04:00
|
|
|
|
nscoord styleFontSize = aFrame->StyleFont()->mFont.size;
|
2011-11-24 06:48:23 +04:00
|
|
|
|
if (styleFontSize <= 0) {
|
|
|
|
|
// Never scale zero font size.
|
|
|
|
|
return 1.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (aMinFontSize <= 0) {
|
|
|
|
|
// No need to scale.
|
|
|
|
|
return 1.0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-13 11:21:39 +04: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;
|
2013-10-01 01:26:04 +04:00
|
|
|
|
f && !f->IsContainerForFontSizeInflation();
|
2012-04-13 11:21:39 +04:00
|
|
|
|
f = f->GetParent()) {
|
|
|
|
|
nsIContent* content = f->GetContent();
|
2012-06-05 03:26:30 +04:00
|
|
|
|
nsIAtom* fType = f->GetType();
|
2015-03-03 08:06:36 +03:00
|
|
|
|
nsIFrame* parent = f->GetParent();
|
2012-04-13 11:21:39 +04:00
|
|
|
|
// Also, if there is more than one frame corresponding to a single
|
|
|
|
|
// content node, we want the outermost one.
|
2015-03-03 08:06:36 +03:00
|
|
|
|
if (!(parent && parent->GetContent() == content) &&
|
2012-06-05 03:26:30 +04: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) {
|
2015-03-03 08:06:36 +03:00
|
|
|
|
// ruby annotations should have the same inflation as its
|
|
|
|
|
// grandparent, which is the ruby frame contains the annotation.
|
|
|
|
|
if (fType == nsGkAtoms::rubyTextFrame) {
|
|
|
|
|
MOZ_ASSERT(parent &&
|
|
|
|
|
parent->GetType() == nsGkAtoms::rubyTextContainerFrame);
|
|
|
|
|
nsIFrame* grandparent = parent->GetParent();
|
|
|
|
|
MOZ_ASSERT(grandparent &&
|
|
|
|
|
grandparent->GetType() == nsGkAtoms::rubyFrame);
|
|
|
|
|
return FontSizeInflationFor(grandparent);
|
|
|
|
|
}
|
2013-02-17 01:51:02 +04:00
|
|
|
|
nsStyleCoord stylePosWidth = f->StylePosition()->mWidth;
|
|
|
|
|
nsStyleCoord stylePosHeight = f->StylePosition()->mHeight;
|
2012-04-13 11:21:39 +04:00
|
|
|
|
if (stylePosWidth.GetUnit() != eStyleUnit_Auto ||
|
|
|
|
|
stylePosHeight.GetUnit() != eStyleUnit_Auto) {
|
|
|
|
|
|
|
|
|
|
return 1.0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t interceptParam = nsLayoutUtils::FontSizeInflationMappingIntercept();
|
2012-10-15 23:03:37 +04:00
|
|
|
|
float maxRatio = (float)nsLayoutUtils::FontSizeInflationMaxRatio() / 100.0f;
|
2012-08-11 22:33:36 +04:00
|
|
|
|
|
2011-11-24 06:48:23 +04:00
|
|
|
|
float ratio = float(styleFontSize) / float(aMinFontSize);
|
2012-10-15 23:03:37 +04:00
|
|
|
|
float inflationRatio;
|
2011-11-24 06:48:23 +04:00
|
|
|
|
|
2012-08-11 22:33:36 +04: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.
|
2012-10-15 23:03:37 +04:00
|
|
|
|
inflationRatio = (1.0f + (ratio * (intercept - 1) / intercept)) / ratio;
|
2012-08-11 22:33:36 +04:00
|
|
|
|
} 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
|
2012-10-15 23:03:37 +04:00
|
|
|
|
inflationRatio = 1 + 1.0f / ratio;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (maxRatio > 1.0 && inflationRatio > maxRatio) {
|
|
|
|
|
return maxRatio;
|
|
|
|
|
} else {
|
|
|
|
|
return inflationRatio;
|
2012-08-11 22:33:36 +04:00
|
|
|
|
}
|
2011-11-24 06:48:23 +04: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...
|
2015-03-10 17:28:23 +03:00
|
|
|
|
// For now, we're going to use NS_FRAME_IN_CONSTRAINED_BSIZE, which
|
2011-11-24 06:48:23 +04:00
|
|
|
|
// indicates whether the frame is inside something with a constrained
|
2015-03-10 17:28:23 +03:00
|
|
|
|
// block-size (propagating down the tree), but the propagation stops when
|
|
|
|
|
// we hit overflow-y [or -x, for vertical mode]: scroll or auto.
|
2013-02-17 01:51:02 +04:00
|
|
|
|
const nsStyleText* styleText = aFrame->StyleText();
|
2012-03-02 21:25:33 +04:00
|
|
|
|
|
|
|
|
|
return styleText->mTextSizeAdjust != NS_STYLE_TEXT_SIZE_ADJUST_NONE &&
|
2015-03-10 17:28:23 +03:00
|
|
|
|
!(aFrame->GetStateBits() & NS_FRAME_IN_CONSTRAINED_BSIZE) &&
|
2012-03-02 21:25:33 +04:00
|
|
|
|
// We also want to disable font inflation for containers that have
|
|
|
|
|
// preformatted text.
|
2014-11-06 16:01:00 +03:00
|
|
|
|
// MathML cells need special treatment. See bug 1002526 comment 56.
|
|
|
|
|
(styleText->WhiteSpaceCanWrap(aFrame) ||
|
|
|
|
|
aFrame->IsFrameOfType(nsIFrame::eMathML));
|
2011-11-24 06:48:23 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nscoord
|
2012-05-21 09:18:28 +04:00
|
|
|
|
nsLayoutUtils::InflationMinFontSizeFor(const nsIFrame *aFrame)
|
2011-11-24 06:48:23 +04:00
|
|
|
|
{
|
2012-05-21 09:18:27 +04:00
|
|
|
|
nsPresContext *presContext = aFrame->PresContext();
|
|
|
|
|
if (!FontSizeInflationEnabled(presContext) ||
|
|
|
|
|
presContext->mInflationDisabledForShrinkWrap) {
|
2011-11-24 06:48:23 +04:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const nsIFrame *f = aFrame; f; f = f->GetParent()) {
|
2013-10-01 01:26:04 +04:00
|
|
|
|
if (f->IsContainerForFontSizeInflation()) {
|
2011-11-24 06:48:23 +04:00
|
|
|
|
if (!ShouldInflateFontsForContainer(f)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-21 09:18:27 +04: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-24 06:48:23 +04:00
|
|
|
|
return MinimumFontSizeFor(aFrame->PresContext(),
|
2015-03-10 17:28:23 +03:00
|
|
|
|
aFrame->GetWritingMode(),
|
|
|
|
|
data->EffectiveISize());
|
2011-11-24 06:48:23 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-10 01:34:50 +03:00
|
|
|
|
MOZ_ASSERT(false, "root should always be container");
|
2011-11-24 06:48:23 +04:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float
|
2012-05-21 09:18:28 +04:00
|
|
|
|
nsLayoutUtils::FontSizeInflationFor(const nsIFrame *aFrame)
|
2011-11-24 06:48:23 +04:00
|
|
|
|
{
|
2013-02-11 10:22:17 +04:00
|
|
|
|
if (aFrame->IsSVGText()) {
|
|
|
|
|
const nsIFrame* container = aFrame;
|
2013-12-20 20:38:51 +04:00
|
|
|
|
while (container->GetType() != nsGkAtoms::svgTextFrame) {
|
2013-02-11 10:22:17 +04:00
|
|
|
|
container = container->GetParent();
|
|
|
|
|
}
|
2013-12-20 20:38:51 +04:00
|
|
|
|
NS_ASSERTION(container, "expected to find an ancestor SVGTextFrame");
|
2013-02-11 10:22:17 +04:00
|
|
|
|
return
|
2013-12-20 20:38:51 +04:00
|
|
|
|
static_cast<const SVGTextFrame*>(container)->GetFontSizeScaleFactor();
|
2013-02-11 10:22:17 +04:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-24 06:48:23 +04:00
|
|
|
|
if (!FontSizeInflationEnabled(aFrame->PresContext())) {
|
2013-02-11 10:22:17 +04:00
|
|
|
|
return 1.0f;
|
2011-11-24 06:48:23 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-21 09:18:28 +04:00
|
|
|
|
return FontSizeInflationInner(aFrame, InflationMinFontSizeFor(aFrame));
|
2011-11-24 06:48:23 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* static */ bool
|
|
|
|
|
nsLayoutUtils::FontSizeInflationEnabled(nsPresContext *aPresContext)
|
|
|
|
|
{
|
2012-06-06 07:47:33 +04:00
|
|
|
|
nsIPresShell* presShell = aPresContext->GetPresShell();
|
|
|
|
|
|
2013-05-16 19:06:03 +04:00
|
|
|
|
if (!presShell) {
|
2012-01-31 02:52:11 +04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2012-08-23 00:17:20 +04:00
|
|
|
|
|
2013-05-16 19:06:03 +04:00
|
|
|
|
return presShell->FontSizeInflationEnabled();
|
2011-11-24 06:48:23 +04:00
|
|
|
|
}
|
2012-12-12 00:36:54 +04:00
|
|
|
|
|
|
|
|
|
/* static */ nsRect
|
|
|
|
|
nsLayoutUtils::GetBoxShadowRectForFrame(nsIFrame* aFrame,
|
|
|
|
|
const nsSize& aFrameSize)
|
|
|
|
|
{
|
2013-02-17 01:51:02 +04:00
|
|
|
|
nsCSSShadowArray* boxShadows = aFrame->StyleBorder()->mBoxShadow;
|
2012-12-12 00:36:54 +04:00
|
|
|
|
if (!boxShadows) {
|
|
|
|
|
return nsRect();
|
|
|
|
|
}
|
2015-06-15 22:02:01 +03:00
|
|
|
|
|
|
|
|
|
bool nativeTheme;
|
|
|
|
|
const nsStyleDisplay* styleDisplay = aFrame->StyleDisplay();
|
|
|
|
|
nsITheme::Transparency transparency;
|
|
|
|
|
if (aFrame->IsThemed(styleDisplay, &transparency)) {
|
|
|
|
|
// For opaque (rectangular) theme widgets we can take the generic
|
|
|
|
|
// border-box path with border-radius disabled.
|
|
|
|
|
nativeTheme = transparency != nsITheme::eOpaque;
|
|
|
|
|
} else {
|
|
|
|
|
nativeTheme = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsRect frameRect = nativeTheme ?
|
|
|
|
|
aFrame->GetVisualOverflowRectRelativeToSelf() :
|
|
|
|
|
nsRect(nsPoint(0, 0), aFrameSize);
|
2012-12-12 00:36:54 +04:00
|
|
|
|
|
|
|
|
|
nsRect shadows;
|
|
|
|
|
int32_t A2D = aFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
|
for (uint32_t i = 0; i < boxShadows->Length(); ++i) {
|
2015-06-15 22:02:01 +03:00
|
|
|
|
nsRect tmpRect = frameRect;
|
2012-12-12 00:36:54 +04:00
|
|
|
|
nsCSSShadowItem* shadow = boxShadows->ShadowAt(i);
|
|
|
|
|
|
|
|
|
|
// inset shadows are never painted outside the frame
|
|
|
|
|
if (shadow->mInset)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
tmpRect.MoveBy(nsPoint(shadow->mXOffset, shadow->mYOffset));
|
|
|
|
|
tmpRect.Inflate(shadow->mSpread);
|
|
|
|
|
tmpRect.Inflate(
|
|
|
|
|
nsContextBoxBlur::GetBlurRadiusMargin(shadow->mRadius, A2D));
|
|
|
|
|
shadows.UnionRect(shadows, tmpRect);
|
|
|
|
|
}
|
|
|
|
|
return shadows;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-15 04:05:05 +04:00
|
|
|
|
/* static */ void
|
|
|
|
|
nsLayoutUtils::UpdateImageVisibilityForFrame(nsIFrame* aImageFrame)
|
|
|
|
|
{
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
nsIAtom* type = aImageFrame->GetType();
|
|
|
|
|
MOZ_ASSERT(type == nsGkAtoms::imageFrame ||
|
|
|
|
|
type == nsGkAtoms::imageControlFrame ||
|
|
|
|
|
type == nsGkAtoms::svgImageFrame, "wrong type of frame");
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> content = do_QueryInterface(aImageFrame->GetContent());
|
|
|
|
|
if (!content) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-15 04:05:06 +04:00
|
|
|
|
nsIPresShell* presShell = aImageFrame->PresContext()->PresShell();
|
|
|
|
|
if (presShell->AssumeAllImagesVisible()) {
|
|
|
|
|
presShell->EnsureImageInVisibleList(content);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-15 04:05:05 +04:00
|
|
|
|
bool visible = true;
|
|
|
|
|
nsIFrame* f = aImageFrame->GetParent();
|
|
|
|
|
nsRect rect = aImageFrame->GetContentRectRelativeToSelf();
|
|
|
|
|
nsIFrame* rectFrame = aImageFrame;
|
|
|
|
|
while (f) {
|
|
|
|
|
nsIScrollableFrame* sf = do_QueryFrame(f);
|
|
|
|
|
if (sf) {
|
|
|
|
|
nsRect transformedRect =
|
|
|
|
|
nsLayoutUtils::TransformFrameRectToAncestor(rectFrame, rect, f);
|
|
|
|
|
if (!sf->IsRectNearlyVisible(transformedRect)) {
|
|
|
|
|
visible = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-09-22 01:20:22 +04:00
|
|
|
|
// Move transformedRect to be contained in the scrollport as best we can
|
|
|
|
|
// (it might not fit) to pretend that it was scrolled into view.
|
|
|
|
|
nsRect scrollPort = sf->GetScrollPortRect();
|
|
|
|
|
if (transformedRect.XMost() > scrollPort.XMost()) {
|
|
|
|
|
transformedRect.x -= transformedRect.XMost() - scrollPort.XMost();
|
|
|
|
|
}
|
|
|
|
|
if (transformedRect.x < scrollPort.x) {
|
|
|
|
|
transformedRect.x = scrollPort.x;
|
|
|
|
|
}
|
|
|
|
|
if (transformedRect.YMost() > scrollPort.YMost()) {
|
|
|
|
|
transformedRect.y -= transformedRect.YMost() - scrollPort.YMost();
|
|
|
|
|
}
|
|
|
|
|
if (transformedRect.y < scrollPort.y) {
|
|
|
|
|
transformedRect.y = scrollPort.y;
|
|
|
|
|
}
|
|
|
|
|
transformedRect.width = std::min(transformedRect.width, scrollPort.width);
|
|
|
|
|
transformedRect.height = std::min(transformedRect.height, scrollPort.height);
|
|
|
|
|
rect = transformedRect;
|
2013-09-15 04:05:05 +04:00
|
|
|
|
rectFrame = f;
|
|
|
|
|
}
|
|
|
|
|
nsIFrame* parent = f->GetParent();
|
|
|
|
|
if (!parent) {
|
|
|
|
|
parent = nsLayoutUtils::GetCrossDocParentFrame(f);
|
|
|
|
|
if (parent && parent->PresContext()->IsChrome()) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
f = parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (visible) {
|
2013-09-15 04:05:06 +04:00
|
|
|
|
presShell->EnsureImageInVisibleList(content);
|
2013-09-15 04:05:05 +04:00
|
|
|
|
} else {
|
2013-09-15 04:05:06 +04:00
|
|
|
|
presShell->RemoveImageFromVisibleList(content);
|
2013-09-15 04:05:05 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-01 01:26:04 +04:00
|
|
|
|
|
2014-07-29 22:50:48 +04:00
|
|
|
|
/* static */ bool
|
2014-09-23 20:17:36 +04:00
|
|
|
|
nsLayoutUtils::GetContentViewerSize(nsPresContext* aPresContext,
|
|
|
|
|
LayoutDeviceIntSize& aOutSize)
|
2014-07-29 22:50:48 +04:00
|
|
|
|
{
|
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = aPresContext->GetDocShell();
|
|
|
|
|
if (!docShell) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
|
docShell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
|
if (!cv) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIntRect bounds;
|
|
|
|
|
cv->GetBounds(bounds);
|
2014-09-23 20:17:36 +04:00
|
|
|
|
aOutSize = LayoutDeviceIntRect::FromUntyped(bounds).Size();
|
2014-07-29 22:50:48 +04:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-07 21:39:20 +03:00
|
|
|
|
static bool
|
|
|
|
|
UpdateCompositionBoundsForRCDRSF(ParentLayerRect& aCompBounds,
|
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
|
const nsRect& aFrameBounds,
|
|
|
|
|
bool aScaleContentViewerSize,
|
|
|
|
|
const LayoutDeviceToLayerScale2D& aCumulativeResolution)
|
|
|
|
|
{
|
|
|
|
|
nsIFrame* rootFrame = aPresContext->PresShell()->GetRootFrame();
|
|
|
|
|
if (!rootFrame) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// On Android, we need to do things a bit differently to get things
|
|
|
|
|
// right (see bug 983208, bug 988882). We use the bounds of the nearest
|
|
|
|
|
// widget, but clamp the height to the frame bounds height. This clamping
|
|
|
|
|
// is done to get correct results for a page where the page is sized to
|
|
|
|
|
// the screen and thus the dynamic toolbar never disappears. In such a
|
|
|
|
|
// case, we want the composition bounds to exclude the toolbar height,
|
|
|
|
|
// but the widget bounds includes it. We don't currently have a good way
|
|
|
|
|
// of knowing about the toolbar height, but clamping to the frame bounds
|
|
|
|
|
// height gives the correct answer in the cases we care about.
|
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
|
nsIWidget* widget = rootFrame->GetNearestWidget();
|
|
|
|
|
#else
|
|
|
|
|
nsView* view = rootFrame->GetView();
|
|
|
|
|
nsIWidget* widget = view ? view->GetWidget() : nullptr;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (widget) {
|
|
|
|
|
nsIntRect widgetBounds;
|
|
|
|
|
widget->GetBounds(widgetBounds);
|
|
|
|
|
widgetBounds.MoveTo(0, 0);
|
|
|
|
|
aCompBounds = ParentLayerRect(ViewAs<ParentLayerPixel>(widgetBounds));
|
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
|
ParentLayerRect frameBounds =
|
|
|
|
|
LayoutDeviceRect::FromAppUnits(aFrameBounds, aPresContext->AppUnitsPerDevPixel())
|
|
|
|
|
* aCumulativeResolution
|
|
|
|
|
* LayerToParentLayerScale(1.0);
|
|
|
|
|
if (frameBounds.height < aCompBounds.height) {
|
|
|
|
|
aCompBounds.height = frameBounds.height;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LayoutDeviceIntSize contentSize;
|
|
|
|
|
if (nsLayoutUtils::GetContentViewerSize(aPresContext, contentSize)) {
|
|
|
|
|
LayoutDeviceToParentLayerScale scale;
|
|
|
|
|
if (aScaleContentViewerSize && aPresContext->GetParentPresContext()) {
|
|
|
|
|
scale = LayoutDeviceToParentLayerScale(
|
|
|
|
|
aPresContext->GetParentPresContext()->PresShell()->GetCumulativeResolution());
|
|
|
|
|
}
|
|
|
|
|
aCompBounds.SizeTo(contentSize * scale);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-22 22:54:11 +03:00
|
|
|
|
/* static */ nsMargin
|
|
|
|
|
nsLayoutUtils::ScrollbarAreaToExcludeFromCompositionBoundsFor(nsIFrame* aScrollFrame)
|
2015-05-07 21:39:19 +03:00
|
|
|
|
{
|
|
|
|
|
if (!aScrollFrame || !aScrollFrame->GetScrollTargetFrame()) {
|
2015-05-22 22:54:11 +03:00
|
|
|
|
return nsMargin();
|
2015-05-07 21:39:19 +03:00
|
|
|
|
}
|
|
|
|
|
nsPresContext* presContext = aScrollFrame->PresContext();
|
|
|
|
|
nsIPresShell* presShell = presContext->GetPresShell();
|
|
|
|
|
if (!presShell) {
|
2015-05-22 22:54:11 +03:00
|
|
|
|
return nsMargin();
|
2015-05-07 21:39:19 +03:00
|
|
|
|
}
|
|
|
|
|
bool isRootScrollFrame = aScrollFrame == presShell->GetRootScrollFrame();
|
|
|
|
|
bool isRootContentDocRootScrollFrame = isRootScrollFrame
|
|
|
|
|
&& presContext->IsRootContentDocument();
|
2015-05-22 22:54:11 +03:00
|
|
|
|
if (!isRootContentDocRootScrollFrame) {
|
|
|
|
|
return nsMargin();
|
|
|
|
|
}
|
|
|
|
|
if (LookAndFeel::GetInt(LookAndFeel::eIntID_UseOverlayScrollbars)) {
|
|
|
|
|
return nsMargin();
|
|
|
|
|
}
|
|
|
|
|
nsIScrollableFrame* scrollableFrame = aScrollFrame->GetScrollTargetFrame();
|
|
|
|
|
if (!scrollableFrame) {
|
|
|
|
|
return nsMargin();
|
|
|
|
|
}
|
|
|
|
|
return scrollableFrame->GetActualScrollbarSizes();
|
2015-05-07 21:39:19 +03:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-27 05:46:23 +04:00
|
|
|
|
/* static */ nsSize
|
2015-05-04 17:17:26 +03:00
|
|
|
|
nsLayoutUtils::CalculateCompositionSizeForFrame(nsIFrame* aFrame, bool aSubtractScrollbars)
|
2014-03-27 05:46:23 +04:00
|
|
|
|
{
|
2015-02-26 01:08:40 +03:00
|
|
|
|
// If we have a scrollable frame, restrict the composition bounds to its
|
|
|
|
|
// scroll port. The scroll port excludes the frame borders and the scroll
|
|
|
|
|
// bars, which we don't want to be part of the composition bounds.
|
|
|
|
|
nsIScrollableFrame* scrollableFrame = aFrame->GetScrollTargetFrame();
|
2015-05-07 21:44:03 +03:00
|
|
|
|
nsRect rect = scrollableFrame ? scrollableFrame->GetScrollPortRect() : aFrame->GetRect();
|
|
|
|
|
nsSize size = rect.Size();
|
2014-03-27 05:46:23 +04:00
|
|
|
|
|
|
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
|
|
|
|
nsIPresShell* presShell = presContext->PresShell();
|
|
|
|
|
|
|
|
|
|
bool isRootContentDocRootScrollFrame = presContext->IsRootContentDocument()
|
|
|
|
|
&& aFrame == presShell->GetRootScrollFrame();
|
|
|
|
|
if (isRootContentDocRootScrollFrame) {
|
2015-05-07 21:39:20 +03:00
|
|
|
|
ParentLayerRect compBounds;
|
2015-05-07 21:44:02 +03:00
|
|
|
|
LayoutDeviceToLayerScale2D cumulativeResolution(
|
|
|
|
|
presShell->GetCumulativeResolution()
|
|
|
|
|
* nsLayoutUtils::GetTransformToAncestorScale(aFrame));
|
2015-05-07 21:44:03 +03:00
|
|
|
|
if (UpdateCompositionBoundsForRCDRSF(compBounds, presContext, rect,
|
2015-05-07 21:44:02 +03:00
|
|
|
|
false, cumulativeResolution)) {
|
2014-07-29 22:50:48 +04:00
|
|
|
|
int32_t auPerDevPixel = presContext->AppUnitsPerDevPixel();
|
2015-05-07 21:39:20 +03:00
|
|
|
|
size = nsSize(compBounds.width * auPerDevPixel, compBounds.height * auPerDevPixel);
|
2015-02-26 01:08:40 +03:00
|
|
|
|
}
|
2014-03-27 05:46:23 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-22 22:54:11 +03:00
|
|
|
|
if (aSubtractScrollbars) {
|
|
|
|
|
nsMargin margins = ScrollbarAreaToExcludeFromCompositionBoundsFor(aFrame);
|
2015-05-07 21:39:19 +03:00
|
|
|
|
size.width -= margins.LeftRight();
|
|
|
|
|
size.height -= margins.TopBottom();
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-27 05:46:23 +04:00
|
|
|
|
return size;
|
|
|
|
|
}
|
2014-07-29 22:50:48 +04:00
|
|
|
|
|
2014-04-04 18:13:09 +04:00
|
|
|
|
/* static */ CSSSize
|
|
|
|
|
nsLayoutUtils::CalculateRootCompositionSize(nsIFrame* aFrame,
|
|
|
|
|
bool aIsRootContentDocRootScrollFrame,
|
|
|
|
|
const FrameMetrics& aMetrics)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (aIsRootContentDocRootScrollFrame) {
|
2015-05-07 21:44:03 +03:00
|
|
|
|
return ViewAs<LayerPixel>(aMetrics.GetCompositionBounds().Size(),
|
2014-04-04 18:13:09 +04:00
|
|
|
|
PixelCastJustification::ParentLayerToLayerForRootComposition)
|
2014-10-24 23:49:38 +04:00
|
|
|
|
* LayerToScreenScale(1.0f)
|
|
|
|
|
/ aMetrics.DisplayportPixelsPerCSSPixel();
|
2014-04-04 18:13:09 +04:00
|
|
|
|
}
|
|
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
2014-10-24 23:49:38 +04:00
|
|
|
|
ScreenSize rootCompositionSize;
|
2014-04-04 18:13:09 +04:00
|
|
|
|
nsPresContext* rootPresContext =
|
|
|
|
|
presContext->GetToplevelContentDocumentPresContext();
|
|
|
|
|
if (!rootPresContext) {
|
|
|
|
|
rootPresContext = presContext->GetRootPresContext();
|
|
|
|
|
}
|
|
|
|
|
nsIPresShell* rootPresShell = nullptr;
|
|
|
|
|
if (rootPresContext) {
|
2015-05-07 21:39:20 +03:00
|
|
|
|
rootPresShell = rootPresContext->PresShell();
|
2014-04-04 18:13:09 +04:00
|
|
|
|
if (nsIFrame* rootFrame = rootPresShell->GetRootFrame()) {
|
2015-03-07 02:07:59 +03:00
|
|
|
|
LayoutDeviceToLayerScale2D cumulativeResolution(
|
|
|
|
|
rootPresShell->GetCumulativeResolution()
|
|
|
|
|
* nsLayoutUtils::GetTransformToAncestorScale(rootFrame));
|
2015-05-07 21:39:20 +03:00
|
|
|
|
ParentLayerRect compBounds;
|
|
|
|
|
if (UpdateCompositionBoundsForRCDRSF(compBounds, rootPresContext,
|
|
|
|
|
rootFrame->GetRect(), true, cumulativeResolution)) {
|
|
|
|
|
rootCompositionSize = ViewAs<ScreenPixel>(compBounds.Size(),
|
|
|
|
|
PixelCastJustification::ScreenIsParentLayerForRoot);
|
2014-07-29 22:50:48 +04:00
|
|
|
|
} else {
|
2015-05-07 21:39:20 +03:00
|
|
|
|
int32_t rootAUPerDevPixel = rootPresContext->AppUnitsPerDevPixel();
|
|
|
|
|
LayerSize frameSize =
|
|
|
|
|
(LayoutDeviceRect::FromAppUnits(rootFrame->GetRect(), rootAUPerDevPixel)
|
|
|
|
|
* cumulativeResolution).Size();
|
|
|
|
|
rootCompositionSize = frameSize * LayerToScreenScale(1.0f);
|
2014-04-04 18:13:09 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
nsIWidget* widget = aFrame->GetNearestWidget();
|
|
|
|
|
nsIntRect widgetBounds;
|
|
|
|
|
widget->GetBounds(widgetBounds);
|
2014-10-24 23:49:38 +04:00
|
|
|
|
rootCompositionSize = ScreenSize(ViewAs<ScreenPixel>(widgetBounds.Size()));
|
2014-04-04 18:13:09 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Adjust composition size for the size of scroll bars.
|
|
|
|
|
nsIFrame* rootRootScrollFrame = rootPresShell ? rootPresShell->GetRootScrollFrame() : nullptr;
|
2015-05-22 22:54:11 +03:00
|
|
|
|
nsMargin scrollbarMargins = ScrollbarAreaToExcludeFromCompositionBoundsFor(rootRootScrollFrame);
|
2015-08-05 21:39:42 +03:00
|
|
|
|
LayoutDeviceMargin margins = LayoutDeviceMargin::FromAppUnits(scrollbarMargins,
|
|
|
|
|
rootPresContext->AppUnitsPerDevPixel());
|
|
|
|
|
// Scrollbars are not subject to resolution scaling, so LD pixels = layer pixels for them.
|
2015-05-22 22:54:11 +03:00
|
|
|
|
rootCompositionSize.width -= margins.LeftRight();
|
|
|
|
|
rootCompositionSize.height -= margins.TopBottom();
|
2014-04-04 18:13:09 +04:00
|
|
|
|
|
2014-10-24 23:49:38 +04:00
|
|
|
|
return rootCompositionSize / aMetrics.DisplayportPixelsPerCSSPixel();
|
2014-04-04 18:13:09 +04:00
|
|
|
|
}
|
2014-03-27 05:46:23 +04:00
|
|
|
|
|
|
|
|
|
/* static */ nsRect
|
|
|
|
|
nsLayoutUtils::CalculateScrollableRectForFrame(nsIScrollableFrame* aScrollableFrame, nsIFrame* aRootFrame)
|
|
|
|
|
{
|
|
|
|
|
nsRect contentBounds;
|
|
|
|
|
if (aScrollableFrame) {
|
|
|
|
|
contentBounds = aScrollableFrame->GetScrollRange();
|
|
|
|
|
|
|
|
|
|
// We ifndef the below code for Fennec because it requires special behaviour
|
|
|
|
|
// on the APZC side. Because Fennec has it's own PZC implementation which doesn't
|
|
|
|
|
// provide the special behaviour, this code will cause it to break. We can remove
|
|
|
|
|
// the ifndef once Fennec switches over to APZ or if we add the special handling
|
|
|
|
|
// to Fennec
|
2014-08-09 01:42:25 +04:00
|
|
|
|
#if !defined(MOZ_WIDGET_ANDROID) || defined(MOZ_ANDROID_APZ)
|
2014-03-27 05:46:23 +04:00
|
|
|
|
nsPoint scrollPosition = aScrollableFrame->GetScrollPosition();
|
|
|
|
|
if (aScrollableFrame->GetScrollbarStyles().mVertical == NS_STYLE_OVERFLOW_HIDDEN) {
|
|
|
|
|
contentBounds.y = scrollPosition.y;
|
|
|
|
|
contentBounds.height = 0;
|
|
|
|
|
}
|
|
|
|
|
if (aScrollableFrame->GetScrollbarStyles().mHorizontal == NS_STYLE_OVERFLOW_HIDDEN) {
|
|
|
|
|
contentBounds.x = scrollPosition.x;
|
|
|
|
|
contentBounds.width = 0;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
contentBounds.width += aScrollableFrame->GetScrollPortRect().width;
|
|
|
|
|
contentBounds.height += aScrollableFrame->GetScrollPortRect().height;
|
|
|
|
|
} else {
|
|
|
|
|
contentBounds = aRootFrame->GetRect();
|
|
|
|
|
}
|
|
|
|
|
return contentBounds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* static */ nsRect
|
|
|
|
|
nsLayoutUtils::CalculateExpandedScrollableRect(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
nsRect scrollableRect =
|
|
|
|
|
CalculateScrollableRectForFrame(aFrame->GetScrollTargetFrame(),
|
|
|
|
|
aFrame->PresContext()->PresShell()->GetRootFrame());
|
|
|
|
|
nsSize compSize = CalculateCompositionSizeForFrame(aFrame);
|
|
|
|
|
|
|
|
|
|
if (aFrame == aFrame->PresContext()->PresShell()->GetRootScrollFrame()) {
|
|
|
|
|
// the composition size for the root scroll frame does not include the
|
|
|
|
|
// local resolution, so we adjust.
|
2015-03-07 02:07:59 +03:00
|
|
|
|
float res = aFrame->PresContext()->PresShell()->GetResolution();
|
|
|
|
|
compSize.width = NSToCoordRound(compSize.width / res);
|
|
|
|
|
compSize.height = NSToCoordRound(compSize.height / res);
|
2014-03-27 05:46:23 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (scrollableRect.width < compSize.width) {
|
|
|
|
|
scrollableRect.x = std::max(0,
|
|
|
|
|
scrollableRect.x - (compSize.width - scrollableRect.width));
|
|
|
|
|
scrollableRect.width = compSize.width;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (scrollableRect.height < compSize.height) {
|
|
|
|
|
scrollableRect.y = std::max(0,
|
|
|
|
|
scrollableRect.y - (compSize.height - scrollableRect.height));
|
|
|
|
|
scrollableRect.height = compSize.height;
|
|
|
|
|
}
|
|
|
|
|
return scrollableRect;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-22 03:48:54 +04:00
|
|
|
|
/* static */ void
|
2014-07-24 07:10:05 +04:00
|
|
|
|
nsLayoutUtils::DoLogTestDataForPaint(LayerManager* aManager,
|
2014-05-29 20:51:28 +04:00
|
|
|
|
ViewID aScrollId,
|
|
|
|
|
const std::string& aKey,
|
|
|
|
|
const std::string& aValue)
|
2014-04-22 03:48:54 +04:00
|
|
|
|
{
|
2014-07-24 07:10:05 +04:00
|
|
|
|
if (aManager->GetBackendType() == LayersBackend::LAYERS_CLIENT) {
|
|
|
|
|
static_cast<ClientLayerManager*>(aManager)->LogTestDataForCurrentPaint(aScrollId, aKey, aValue);
|
2014-04-22 03:48:54 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-03 22:13:05 +04:00
|
|
|
|
/* static */ bool
|
|
|
|
|
nsLayoutUtils::IsAPZTestLoggingEnabled()
|
|
|
|
|
{
|
|
|
|
|
return gfxPrefs::APZTestLoggingEnabled();
|
|
|
|
|
}
|
2014-04-04 18:13:30 +04:00
|
|
|
|
|
2013-10-01 01:26:04 +04:00
|
|
|
|
nsLayoutUtils::SurfaceFromElementResult::SurfaceFromElementResult()
|
|
|
|
|
// Use safe default values here
|
2014-04-17 09:29:52 +04:00
|
|
|
|
: mIsWriteOnly(true)
|
|
|
|
|
, mIsStillLoading(false)
|
2015-05-07 19:25:10 +03:00
|
|
|
|
, mHasSize(false)
|
2014-04-17 09:29:52 +04:00
|
|
|
|
, mCORSUsed(false)
|
|
|
|
|
, mIsPremultiplied(true)
|
2013-10-01 01:26:04 +04:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
nsLayoutUtils::IsNonWrapperBlock(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
return GetAsBlock(aFrame) && !aFrame->IsBlockWrapper();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
nsLayoutUtils::NeedsPrintPreviewBackground(nsPresContext* aPresContext)
|
|
|
|
|
{
|
|
|
|
|
return aPresContext->IsRootPaginatedDocument() &&
|
|
|
|
|
(aPresContext->Type() == nsPresContext::eContext_PrintPreview ||
|
|
|
|
|
aPresContext->Type() == nsPresContext::eContext_PageLayout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AutoMaybeDisableFontInflation::AutoMaybeDisableFontInflation(nsIFrame *aFrame)
|
|
|
|
|
{
|
|
|
|
|
// FIXME: Now that inflation calculations are based on the flow
|
|
|
|
|
// root's NCA's (nearest common ancestor of its inflatable
|
|
|
|
|
// descendants) width, we could probably disable inflation in
|
|
|
|
|
// fewer cases than we currently do.
|
2014-11-06 16:01:00 +03:00
|
|
|
|
// MathML cells need special treatment. See bug 1002526 comment 56.
|
|
|
|
|
if (aFrame->IsContainerForFontSizeInflation() &&
|
|
|
|
|
!aFrame->IsFrameOfType(nsIFrame::eMathML)) {
|
2013-10-01 01:26:04 +04:00
|
|
|
|
mPresContext = aFrame->PresContext();
|
|
|
|
|
mOldValue = mPresContext->mInflationDisabledForShrinkWrap;
|
|
|
|
|
mPresContext->mInflationDisabledForShrinkWrap = true;
|
|
|
|
|
} else {
|
|
|
|
|
// indicate we have nothing to restore
|
|
|
|
|
mPresContext = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AutoMaybeDisableFontInflation::~AutoMaybeDisableFontInflation()
|
|
|
|
|
{
|
|
|
|
|
if (mPresContext) {
|
|
|
|
|
mPresContext->mInflationDisabledForShrinkWrap = mOldValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-05-29 01:43:39 +04:00
|
|
|
|
|
|
|
|
|
namespace mozilla {
|
2014-10-17 18:06:34 +04:00
|
|
|
|
|
2014-10-19 14:47:22 +04:00
|
|
|
|
Rect NSRectToRect(const nsRect& aRect, double aAppUnitsPerPixel)
|
2014-10-17 18:06:34 +04:00
|
|
|
|
{
|
2014-10-19 14:47:22 +04:00
|
|
|
|
// Note that by making aAppUnitsPerPixel a double we're doing floating-point
|
|
|
|
|
// division using a larger type and avoiding rounding error.
|
|
|
|
|
return Rect(Float(aRect.x / aAppUnitsPerPixel),
|
|
|
|
|
Float(aRect.y / aAppUnitsPerPixel),
|
|
|
|
|
Float(aRect.width / aAppUnitsPerPixel),
|
|
|
|
|
Float(aRect.height / aAppUnitsPerPixel));
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-22 15:29:06 +04:00
|
|
|
|
Rect NSRectToSnappedRect(const nsRect& aRect, double aAppUnitsPerPixel,
|
|
|
|
|
const gfx::DrawTarget& aSnapDT)
|
2014-10-19 14:47:22 +04:00
|
|
|
|
{
|
|
|
|
|
// Note that by making aAppUnitsPerPixel a double we're doing floating-point
|
|
|
|
|
// division using a larger type and avoiding rounding error.
|
|
|
|
|
Rect rect(Float(aRect.x / aAppUnitsPerPixel),
|
|
|
|
|
Float(aRect.y / aAppUnitsPerPixel),
|
|
|
|
|
Float(aRect.width / aAppUnitsPerPixel),
|
|
|
|
|
Float(aRect.height / aAppUnitsPerPixel));
|
|
|
|
|
MaybeSnapToDevicePixels(rect, aSnapDT, true);
|
|
|
|
|
return rect;
|
2014-10-17 18:06:34 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-20 13:55:48 +04:00
|
|
|
|
void StrokeLineWithSnapping(const nsPoint& aP1, const nsPoint& aP2,
|
|
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
|
DrawTarget& aDrawTarget,
|
|
|
|
|
const Pattern& aPattern,
|
|
|
|
|
const StrokeOptions& aStrokeOptions,
|
|
|
|
|
const DrawOptions& aDrawOptions)
|
|
|
|
|
{
|
|
|
|
|
Point p1 = NSPointToPoint(aP1, aAppUnitsPerDevPixel);
|
|
|
|
|
Point p2 = NSPointToPoint(aP2, aAppUnitsPerDevPixel);
|
2015-07-07 21:56:23 +03:00
|
|
|
|
SnapLineToDevicePixelsForStroking(p1, p2, aDrawTarget,
|
|
|
|
|
aStrokeOptions.mLineWidth);
|
2014-10-20 13:55:48 +04:00
|
|
|
|
aDrawTarget.StrokeLine(p1, p2, aPattern, aStrokeOptions, aDrawOptions);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-29 01:43:39 +04:00
|
|
|
|
namespace layout {
|
|
|
|
|
|
2014-10-17 18:06:34 +04:00
|
|
|
|
|
2014-05-29 01:43:39 +04:00
|
|
|
|
void
|
|
|
|
|
MaybeSetupTransactionIdAllocator(layers::LayerManager* aManager, nsView* aView)
|
|
|
|
|
{
|
|
|
|
|
if (aManager->GetBackendType() == layers::LayersBackend::LAYERS_CLIENT) {
|
|
|
|
|
layers::ClientLayerManager *manager = static_cast<layers::ClientLayerManager*>(aManager);
|
|
|
|
|
nsRefreshDriver *refresh = aView->GetViewManager()->GetPresShell()->GetPresContext()->RefreshDriver();
|
|
|
|
|
manager->SetTransactionIdAllocator(refresh);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
|
} // namespace layout
|
|
|
|
|
} // namespace mozilla
|
2014-06-26 16:48:05 +04:00
|
|
|
|
|
|
|
|
|
/* static */ bool
|
|
|
|
|
nsLayoutUtils::IsOutlineStyleAutoEnabled()
|
|
|
|
|
{
|
|
|
|
|
static bool sOutlineStyleAutoEnabled;
|
|
|
|
|
static bool sOutlineStyleAutoPrefCached = false;
|
|
|
|
|
|
|
|
|
|
if (!sOutlineStyleAutoPrefCached) {
|
|
|
|
|
sOutlineStyleAutoPrefCached = true;
|
|
|
|
|
Preferences::AddBoolVarCache(&sOutlineStyleAutoEnabled,
|
|
|
|
|
"layout.css.outline-style-auto.enabled",
|
|
|
|
|
false);
|
|
|
|
|
}
|
|
|
|
|
return sOutlineStyleAutoEnabled;
|
|
|
|
|
}
|
2014-08-15 21:34:20 +04:00
|
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
|
nsLayoutUtils::SetBSizeFromFontMetrics(const nsIFrame* aFrame,
|
|
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
2015-01-15 12:02:11 +03:00
|
|
|
|
const LogicalMargin& aFramePadding,
|
2014-08-15 21:34:20 +04:00
|
|
|
|
WritingMode aLineWM,
|
|
|
|
|
WritingMode aFrameWM)
|
|
|
|
|
{
|
|
|
|
|
nsRefPtr<nsFontMetrics> fm;
|
|
|
|
|
float inflation = nsLayoutUtils::FontSizeInflationFor(aFrame);
|
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(aFrame, getter_AddRefs(fm), inflation);
|
|
|
|
|
|
|
|
|
|
if (fm) {
|
|
|
|
|
// Compute final height of the frame.
|
|
|
|
|
//
|
|
|
|
|
// Do things the standard css2 way -- though it's hard to find it
|
|
|
|
|
// in the css2 spec! It's actually found in the css1 spec section
|
|
|
|
|
// 4.4 (you will have to read between the lines to really see
|
|
|
|
|
// it).
|
|
|
|
|
//
|
|
|
|
|
// The height of our box is the sum of our font size plus the top
|
|
|
|
|
// and bottom border and padding. The height of children do not
|
|
|
|
|
// affect our height.
|
2014-11-13 11:58:06 +03:00
|
|
|
|
aMetrics.SetBlockStartAscent(aLineWM.IsLineInverted() ? fm->MaxDescent()
|
|
|
|
|
: fm->MaxAscent());
|
2014-08-15 21:34:20 +04:00
|
|
|
|
aMetrics.BSize(aLineWM) = fm->MaxHeight();
|
|
|
|
|
} else {
|
|
|
|
|
NS_WARNING("Cannot get font metrics - defaulting sizes to 0");
|
|
|
|
|
aMetrics.SetBlockStartAscent(aMetrics.BSize(aLineWM) = 0);
|
|
|
|
|
}
|
|
|
|
|
aMetrics.SetBlockStartAscent(aMetrics.BlockStartAscent() +
|
|
|
|
|
aFramePadding.BStart(aFrameWM));
|
2015-01-15 12:02:11 +03:00
|
|
|
|
aMetrics.BSize(aLineWM) += aFramePadding.BStartEnd(aFrameWM);
|
2014-08-15 21:34:20 +04:00
|
|
|
|
}
|
2015-02-11 00:28:07 +03:00
|
|
|
|
|
|
|
|
|
/* static */ bool
|
|
|
|
|
nsLayoutUtils::HasApzAwareListeners(EventListenerManager* aElm)
|
|
|
|
|
{
|
|
|
|
|
if (!aElm) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return aElm->HasListenersFor(nsGkAtoms::ontouchstart) ||
|
|
|
|
|
aElm->HasListenersFor(nsGkAtoms::ontouchmove) ||
|
|
|
|
|
aElm->HasListenersFor(nsGkAtoms::onwheel) ||
|
|
|
|
|
aElm->HasListenersFor(nsGkAtoms::onDOMMouseScroll) ||
|
2015-06-30 13:43:08 +03:00
|
|
|
|
aElm->HasListenersFor(nsHtml5Atoms::onmousewheel) ||
|
|
|
|
|
aElm->HasListenersFor(nsGkAtoms::onMozMousePixelScroll);
|
2015-02-11 00:28:07 +03:00
|
|
|
|
}
|
2015-02-11 00:28:07 +03:00
|
|
|
|
|
|
|
|
|
/* static */ bool
|
|
|
|
|
nsLayoutUtils::HasDocumentLevelListenersForApzAwareEvents(nsIPresShell* aShell)
|
|
|
|
|
{
|
|
|
|
|
if (nsIDocument* doc = aShell->GetDocument()) {
|
|
|
|
|
WidgetEvent event(true, NS_EVENT_NULL);
|
|
|
|
|
nsTArray<EventTarget*> targets;
|
|
|
|
|
nsresult rv = EventDispatcher::Dispatch(doc, nullptr, &event, nullptr,
|
|
|
|
|
nullptr, nullptr, &targets);
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
for (size_t i = 0; i < targets.Length(); i++) {
|
|
|
|
|
if (HasApzAwareListeners(targets[i]->GetExistingListenerManager())) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-03-24 16:13:24 +03:00
|
|
|
|
|
2015-04-11 02:33:56 +03:00
|
|
|
|
/* static */ float
|
|
|
|
|
nsLayoutUtils::GetResolution(nsIPresShell* aPresShell)
|
|
|
|
|
{
|
|
|
|
|
nsIScrollableFrame* sf = aPresShell->GetRootScrollFrameAsScrollable();
|
|
|
|
|
if (sf) {
|
|
|
|
|
return sf->GetResolution();
|
|
|
|
|
}
|
|
|
|
|
return aPresShell->GetResolution();
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-14 20:19:10 +03:00
|
|
|
|
/* static */ void
|
|
|
|
|
nsLayoutUtils::SetResolutionAndScaleTo(nsIPresShell* aPresShell, float aResolution)
|
|
|
|
|
{
|
|
|
|
|
nsIScrollableFrame* sf = aPresShell->GetRootScrollFrameAsScrollable();
|
|
|
|
|
if (sf) {
|
|
|
|
|
sf->SetResolutionAndScaleTo(aResolution);
|
|
|
|
|
aPresShell->SetResolutionAndScaleTo(aResolution);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
MaybeReflowForInflationScreenSizeChange(nsPresContext *aPresContext)
|
|
|
|
|
{
|
|
|
|
|
if (aPresContext) {
|
|
|
|
|
nsIPresShell* presShell = aPresContext->GetPresShell();
|
|
|
|
|
bool fontInflationWasEnabled = presShell->FontSizeInflationEnabled();
|
|
|
|
|
presShell->NotifyFontSizeInflationEnabledIsDirty();
|
|
|
|
|
bool changed = false;
|
|
|
|
|
if (presShell && presShell->FontSizeInflationEnabled() &&
|
|
|
|
|
presShell->FontSizeInflationMinTwips() != 0) {
|
|
|
|
|
aPresContext->ScreenSizeInchesForFontInflation(&changed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
changed = changed ||
|
|
|
|
|
(fontInflationWasEnabled != presShell->FontSizeInflationEnabled());
|
|
|
|
|
if (changed) {
|
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = aPresContext->GetDocShell();
|
|
|
|
|
if (docShell) {
|
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
|
docShell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
|
if (cv) {
|
|
|
|
|
nsTArray<nsCOMPtr<nsIContentViewer> > array;
|
|
|
|
|
cv->AppendSubtree(array);
|
|
|
|
|
for (uint32_t i = 0, iEnd = array.Length(); i < iEnd; ++i) {
|
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
|
nsCOMPtr<nsIContentViewer> cv = array[i];
|
|
|
|
|
cv->GetPresShell(getter_AddRefs(shell));
|
|
|
|
|
if (shell) {
|
|
|
|
|
nsIFrame *rootFrame = shell->GetRootFrame();
|
|
|
|
|
if (rootFrame) {
|
|
|
|
|
shell->FrameNeedsReflow(rootFrame,
|
|
|
|
|
nsIPresShell::eStyleChange,
|
|
|
|
|
NS_FRAME_IS_DIRTY);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
|
nsLayoutUtils::SetScrollPositionClampingScrollPortSize(nsIPresShell* aPresShell, CSSSize aSize)
|
|
|
|
|
{
|
|
|
|
|
MOZ_ASSERT(aSize.width >= 0.0 && aSize.height >= 0.0);
|
|
|
|
|
|
|
|
|
|
aPresShell->SetScrollPositionClampingScrollPortSize(
|
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(aSize.width),
|
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(aSize.height));
|
|
|
|
|
|
|
|
|
|
// When the "font.size.inflation.minTwips" preference is set, the
|
|
|
|
|
// layout depends on the size of the screen. Since when the size
|
|
|
|
|
// of the screen changes, the scroll position clamping scroll port
|
|
|
|
|
// size also changes, we hook in the needed updates here rather
|
|
|
|
|
// than adding a separate notification just for this change.
|
|
|
|
|
nsPresContext* presContext = aPresShell->GetPresContext();
|
|
|
|
|
MaybeReflowForInflationScreenSizeChange(presContext);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
|
nsLayoutUtils::SetCSSViewport(nsIPresShell* aPresShell, CSSSize aSize)
|
|
|
|
|
{
|
|
|
|
|
MOZ_ASSERT(aSize.width >= 0.0 && aSize.height >= 0.0);
|
|
|
|
|
|
|
|
|
|
nscoord width = nsPresContext::CSSPixelsToAppUnits(aSize.width);
|
|
|
|
|
nscoord height = nsPresContext::CSSPixelsToAppUnits(aSize.height);
|
|
|
|
|
|
|
|
|
|
aPresShell->ResizeReflowOverride(width, height);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-21 06:48:10 +03:00
|
|
|
|
/* static */ FrameMetrics
|
|
|
|
|
nsLayoutUtils::ComputeFrameMetrics(nsIFrame* aForFrame,
|
|
|
|
|
nsIFrame* aScrollFrame,
|
|
|
|
|
nsIContent* aContent,
|
|
|
|
|
const nsIFrame* aReferenceFrame,
|
|
|
|
|
Layer* aLayer,
|
|
|
|
|
ViewID aScrollParentId,
|
|
|
|
|
const nsRect& aViewport,
|
2015-05-26 22:40:24 +03:00
|
|
|
|
const Maybe<nsRect>& aClipRect,
|
2015-06-08 23:01:26 +03:00
|
|
|
|
bool aIsRootContent,
|
2015-04-21 06:48:10 +03:00
|
|
|
|
const ContainerLayerParameters& aContainerParameters)
|
|
|
|
|
{
|
|
|
|
|
nsPresContext* presContext = aForFrame->PresContext();
|
|
|
|
|
int32_t auPerDevPixel = presContext->AppUnitsPerDevPixel();
|
|
|
|
|
|
|
|
|
|
nsIPresShell* presShell = presContext->GetPresShell();
|
|
|
|
|
FrameMetrics metrics;
|
|
|
|
|
metrics.SetViewport(CSSRect::FromAppUnits(aViewport));
|
|
|
|
|
|
|
|
|
|
ViewID scrollId = FrameMetrics::NULL_SCROLL_ID;
|
|
|
|
|
if (aContent) {
|
|
|
|
|
scrollId = nsLayoutUtils::FindOrCreateIDFor(aContent);
|
|
|
|
|
nsRect dp;
|
|
|
|
|
if (nsLayoutUtils::GetDisplayPort(aContent, &dp)) {
|
|
|
|
|
metrics.SetDisplayPort(CSSRect::FromAppUnits(dp));
|
|
|
|
|
nsLayoutUtils::LogTestDataForPaint(aLayer->Manager(), scrollId, "displayport",
|
|
|
|
|
metrics.GetDisplayPort());
|
|
|
|
|
}
|
|
|
|
|
if (nsLayoutUtils::GetCriticalDisplayPort(aContent, &dp)) {
|
|
|
|
|
metrics.SetCriticalDisplayPort(CSSRect::FromAppUnits(dp));
|
|
|
|
|
}
|
|
|
|
|
DisplayPortMarginsPropertyData* marginsData =
|
|
|
|
|
static_cast<DisplayPortMarginsPropertyData*>(aContent->GetProperty(nsGkAtoms::DisplayPortMargins));
|
|
|
|
|
if (marginsData) {
|
|
|
|
|
metrics.SetDisplayPortMargins(marginsData->mMargins);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIScrollableFrame* scrollableFrame = nullptr;
|
|
|
|
|
if (aScrollFrame)
|
|
|
|
|
scrollableFrame = aScrollFrame->GetScrollTargetFrame();
|
|
|
|
|
|
|
|
|
|
metrics.SetScrollableRect(CSSRect::FromAppUnits(
|
|
|
|
|
nsLayoutUtils::CalculateScrollableRectForFrame(scrollableFrame, aForFrame)));
|
|
|
|
|
|
|
|
|
|
if (scrollableFrame) {
|
|
|
|
|
nsPoint scrollPosition = scrollableFrame->GetScrollPosition();
|
|
|
|
|
metrics.SetScrollOffset(CSSPoint::FromAppUnits(scrollPosition));
|
|
|
|
|
|
|
|
|
|
nsPoint smoothScrollPosition = scrollableFrame->LastScrollDestination();
|
|
|
|
|
metrics.SetSmoothScrollOffset(CSSPoint::FromAppUnits(smoothScrollPosition));
|
|
|
|
|
|
|
|
|
|
// If the frame was scrolled since the last layers update, and by
|
|
|
|
|
// something other than the APZ code, we want to tell the APZ to update
|
|
|
|
|
// its scroll offset.
|
|
|
|
|
nsIAtom* lastScrollOrigin = scrollableFrame->LastScrollOrigin();
|
|
|
|
|
if (lastScrollOrigin && lastScrollOrigin != nsGkAtoms::apz) {
|
|
|
|
|
metrics.SetScrollOffsetUpdated(scrollableFrame->CurrentScrollGeneration());
|
|
|
|
|
}
|
|
|
|
|
nsIAtom* lastSmoothScrollOrigin = scrollableFrame->LastSmoothScrollOrigin();
|
|
|
|
|
if (lastSmoothScrollOrigin) {
|
|
|
|
|
metrics.SetSmoothScrollOffsetUpdated(scrollableFrame->CurrentScrollGeneration());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsSize lineScrollAmount = scrollableFrame->GetLineScrollAmount();
|
|
|
|
|
LayoutDeviceIntSize lineScrollAmountInDevPixels =
|
|
|
|
|
LayoutDeviceIntSize::FromAppUnitsRounded(lineScrollAmount, presContext->AppUnitsPerDevPixel());
|
|
|
|
|
metrics.SetLineScrollAmount(lineScrollAmountInDevPixels);
|
|
|
|
|
|
|
|
|
|
nsSize pageScrollAmount = scrollableFrame->GetPageScrollAmount();
|
|
|
|
|
LayoutDeviceIntSize pageScrollAmountInDevPixels =
|
|
|
|
|
LayoutDeviceIntSize::FromAppUnitsRounded(pageScrollAmount, presContext->AppUnitsPerDevPixel());
|
|
|
|
|
metrics.SetPageScrollAmount(pageScrollAmountInDevPixels);
|
|
|
|
|
|
|
|
|
|
if (!aScrollFrame->GetParent() ||
|
|
|
|
|
EventStateManager::CanVerticallyScrollFrameWithWheel(aScrollFrame->GetParent()))
|
|
|
|
|
{
|
|
|
|
|
metrics.SetAllowVerticalScrollWithWheel();
|
|
|
|
|
}
|
2015-06-03 02:34:46 +03:00
|
|
|
|
|
|
|
|
|
metrics.SetUsesContainerScrolling(scrollableFrame->UsesContainerScrolling());
|
2015-04-21 06:48:10 +03:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-05 15:36:52 +03:00
|
|
|
|
// If we have the scrollparent being the same as the scroll id, the
|
|
|
|
|
// compositor-side code could get into an infinite loop while building the
|
|
|
|
|
// overscroll handoff chain.
|
|
|
|
|
MOZ_ASSERT(aScrollParentId == FrameMetrics::NULL_SCROLL_ID || scrollId != aScrollParentId);
|
2015-04-21 06:48:10 +03:00
|
|
|
|
metrics.SetScrollId(scrollId);
|
2015-06-08 23:01:26 +03:00
|
|
|
|
metrics.SetIsRootContent(aIsRootContent);
|
2015-04-21 06:48:10 +03:00
|
|
|
|
metrics.SetScrollParentId(aScrollParentId);
|
|
|
|
|
|
2015-05-31 22:44:41 +03:00
|
|
|
|
if (scrollId != FrameMetrics::NULL_SCROLL_ID && !presContext->GetParentPresContext()) {
|
|
|
|
|
if ((aScrollFrame && (aScrollFrame == presShell->GetRootScrollFrame())) ||
|
|
|
|
|
aContent == presShell->GetDocument()->GetDocumentElement()) {
|
|
|
|
|
metrics.SetIsLayersIdRoot(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-21 06:48:10 +03:00
|
|
|
|
// Only the root scrollable frame for a given presShell should pick up
|
|
|
|
|
// the presShell's resolution. All the other frames are 1.0.
|
|
|
|
|
if (aScrollFrame == presShell->GetRootScrollFrame()) {
|
|
|
|
|
metrics.SetPresShellResolution(presShell->GetResolution());
|
|
|
|
|
} else {
|
|
|
|
|
metrics.SetPresShellResolution(1.0f);
|
|
|
|
|
}
|
|
|
|
|
// The cumulative resolution is the resolution at which the scroll frame's
|
|
|
|
|
// content is actually rendered. It includes the pres shell resolutions of
|
|
|
|
|
// all the pres shells from here up to the root, as well as any css-driven
|
|
|
|
|
// resolution. We don't need to compute it as it's already stored in the
|
|
|
|
|
// container parameters.
|
|
|
|
|
metrics.SetCumulativeResolution(aContainerParameters.Scale());
|
|
|
|
|
|
|
|
|
|
LayoutDeviceToScreenScale2D resolutionToScreen(
|
|
|
|
|
presShell->GetCumulativeResolution()
|
|
|
|
|
* nsLayoutUtils::GetTransformToAncestorScale(aScrollFrame ? aScrollFrame : aForFrame));
|
|
|
|
|
metrics.SetExtraResolution(metrics.GetCumulativeResolution() / resolutionToScreen);
|
|
|
|
|
|
|
|
|
|
metrics.SetDevPixelsPerCSSPixel(CSSToLayoutDeviceScale(
|
|
|
|
|
(float)nsPresContext::AppUnitsPerCSSPixel() / auPerDevPixel));
|
|
|
|
|
|
|
|
|
|
// Initially, AsyncPanZoomController should render the content to the screen
|
|
|
|
|
// at the painted resolution.
|
|
|
|
|
const LayerToParentLayerScale layerToParentLayerScale(1.0f);
|
|
|
|
|
metrics.SetZoom(metrics.GetCumulativeResolution() * metrics.GetDevPixelsPerCSSPixel()
|
|
|
|
|
* layerToParentLayerScale);
|
|
|
|
|
|
|
|
|
|
// Calculate the composition bounds as the size of the scroll frame and
|
|
|
|
|
// its origin relative to the reference frame.
|
|
|
|
|
// If aScrollFrame is null, we are in a document without a root scroll frame,
|
|
|
|
|
// so it's a xul document. In this case, use the size of the viewport frame.
|
|
|
|
|
nsIFrame* frameForCompositionBoundsCalculation = aScrollFrame ? aScrollFrame : aForFrame;
|
|
|
|
|
nsRect compositionBounds(frameForCompositionBoundsCalculation->GetOffsetToCrossDoc(aReferenceFrame),
|
|
|
|
|
frameForCompositionBoundsCalculation->GetSize());
|
|
|
|
|
if (scrollableFrame) {
|
|
|
|
|
// If we have a scrollable frame, restrict the composition bounds to its
|
|
|
|
|
// scroll port. The scroll port excludes the frame borders and the scroll
|
|
|
|
|
// bars, which we don't want to be part of the composition bounds.
|
|
|
|
|
nsRect scrollPort = scrollableFrame->GetScrollPortRect();
|
|
|
|
|
compositionBounds = nsRect(compositionBounds.TopLeft() + scrollPort.TopLeft(),
|
|
|
|
|
scrollPort.Size());
|
|
|
|
|
}
|
|
|
|
|
ParentLayerRect frameBounds = LayoutDeviceRect::FromAppUnits(compositionBounds, auPerDevPixel)
|
|
|
|
|
* metrics.GetCumulativeResolution()
|
|
|
|
|
* layerToParentLayerScale;
|
|
|
|
|
|
2015-05-26 22:40:24 +03:00
|
|
|
|
if (aClipRect) {
|
|
|
|
|
ParentLayerRect rect = LayoutDeviceRect::FromAppUnits(*aClipRect, auPerDevPixel)
|
|
|
|
|
* metrics.GetCumulativeResolution()
|
|
|
|
|
* layerToParentLayerScale;
|
|
|
|
|
metrics.SetClipRect(Some(RoundedToInt(rect)));
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-21 06:48:10 +03:00
|
|
|
|
// For the root scroll frame of the root content document (RCD-RSF), the above calculation
|
|
|
|
|
// will yield the size of the viewport frame as the composition bounds, which
|
|
|
|
|
// doesn't actually correspond to what is visible when
|
|
|
|
|
// nsIDOMWindowUtils::setCSSViewport has been called to modify the visible area of
|
|
|
|
|
// the prescontext that the viewport frame is reflowed into. In that case if our
|
|
|
|
|
// document has a widget then the widget's bounds will correspond to what is
|
|
|
|
|
// visible. If we don't have a widget the root view's bounds correspond to what
|
|
|
|
|
// would be visible because they don't get modified by setCSSViewport.
|
|
|
|
|
bool isRootScrollFrame = aScrollFrame == presShell->GetRootScrollFrame();
|
|
|
|
|
bool isRootContentDocRootScrollFrame = isRootScrollFrame
|
|
|
|
|
&& presContext->IsRootContentDocument();
|
|
|
|
|
if (isRootContentDocRootScrollFrame) {
|
2015-05-07 21:44:03 +03:00
|
|
|
|
UpdateCompositionBoundsForRCDRSF(frameBounds, presContext,
|
2015-05-07 21:39:20 +03:00
|
|
|
|
compositionBounds, true, metrics.GetCumulativeResolution());
|
2015-04-21 06:48:10 +03:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-22 22:54:11 +03:00
|
|
|
|
nsMargin sizes = ScrollbarAreaToExcludeFromCompositionBoundsFor(aScrollFrame);
|
2015-08-05 21:39:42 +03:00
|
|
|
|
// Scrollbars are not subject to resolution scaling, so LD pixels = layer pixels for them.
|
|
|
|
|
ParentLayerMargin boundMargins = LayoutDeviceMargin::FromAppUnits(sizes, auPerDevPixel)
|
|
|
|
|
* LayoutDeviceToParentLayerScale(1.0f);
|
2015-05-22 22:54:11 +03:00
|
|
|
|
frameBounds.Deflate(boundMargins);
|
2015-05-07 21:39:19 +03:00
|
|
|
|
|
2015-05-07 21:44:03 +03:00
|
|
|
|
metrics.SetCompositionBounds(frameBounds);
|
|
|
|
|
|
2015-04-21 06:48:10 +03:00
|
|
|
|
metrics.SetRootCompositionSize(
|
|
|
|
|
nsLayoutUtils::CalculateRootCompositionSize(aScrollFrame ? aScrollFrame : aForFrame,
|
|
|
|
|
isRootContentDocRootScrollFrame, metrics));
|
|
|
|
|
|
2015-06-11 03:47:56 +03:00
|
|
|
|
if (gfxPrefs::APZPrintTree() || gfxPrefs::APZTestLoggingEnabled()) {
|
2015-04-21 06:48:10 +03:00
|
|
|
|
if (nsIContent* content = frameForCompositionBoundsCalculation->GetContent()) {
|
|
|
|
|
nsAutoString contentDescription;
|
|
|
|
|
content->Describe(contentDescription);
|
|
|
|
|
metrics.SetContentDescription(NS_LossyConvertUTF16toASCII(contentDescription));
|
2015-06-11 03:47:56 +03:00
|
|
|
|
nsLayoutUtils::LogTestDataForPaint(aLayer->Manager(), scrollId, "contentDescription",
|
|
|
|
|
metrics.GetContentDescription().get());
|
2015-04-21 06:48:10 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
metrics.SetPresShellId(presShell->GetPresShellId());
|
|
|
|
|
|
|
|
|
|
// If the scroll frame's content is marked 'scrollgrab', record this
|
|
|
|
|
// in the FrameMetrics so APZ knows to provide the scroll grabbing
|
|
|
|
|
// behaviour.
|
|
|
|
|
if (aScrollFrame && nsContentUtils::HasScrollgrab(aScrollFrame->GetContent())) {
|
|
|
|
|
metrics.SetHasScrollgrab(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Also compute and set the background color.
|
|
|
|
|
// This is needed for APZ overscrolling support.
|
|
|
|
|
if (aScrollFrame) {
|
|
|
|
|
if (isRootScrollFrame) {
|
|
|
|
|
metrics.SetBackgroundColor(presShell->GetCanvasBackground());
|
|
|
|
|
} else {
|
|
|
|
|
nsStyleContext* backgroundStyle;
|
|
|
|
|
if (nsCSSRendering::FindBackground(aScrollFrame, &backgroundStyle)) {
|
|
|
|
|
metrics.SetBackgroundColor(backgroundStyle->StyleBackground()->mBackgroundColor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return metrics;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-31 08:50:21 +03:00
|
|
|
|
/* static */ bool
|
|
|
|
|
nsLayoutUtils::ContainsMetricsWithId(const Layer* aLayer, const ViewID& aScrollId)
|
|
|
|
|
{
|
|
|
|
|
for (uint32_t i = aLayer->GetFrameMetricsCount(); i > 0; i--) {
|
|
|
|
|
if (aLayer->GetFrameMetrics(i-1).GetScrollId() == aScrollId) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (Layer* child = aLayer->GetFirstChild(); child; child = child->GetNextSibling()) {
|
|
|
|
|
if (ContainsMetricsWithId(child, aScrollId)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-24 16:13:24 +03:00
|
|
|
|
/* static */ uint32_t
|
|
|
|
|
nsLayoutUtils::GetTouchActionFromFrame(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
// If aFrame is null then return default value
|
|
|
|
|
if (!aFrame) {
|
|
|
|
|
return NS_STYLE_TOUCH_ACTION_AUTO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The touch-action CSS property applies to: all elements except:
|
|
|
|
|
// non-replaced inline elements, table rows, row groups, table columns, and column groups
|
|
|
|
|
bool isNonReplacedInlineElement = aFrame->IsFrameOfType(nsIFrame::eLineParticipant);
|
|
|
|
|
if (isNonReplacedInlineElement) {
|
|
|
|
|
return NS_STYLE_TOUCH_ACTION_AUTO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const nsStyleDisplay* disp = aFrame->StyleDisplay();
|
|
|
|
|
bool isTableElement = disp->IsInnerTableStyle() &&
|
|
|
|
|
disp->mDisplay != NS_STYLE_DISPLAY_TABLE_CELL &&
|
|
|
|
|
disp->mDisplay != NS_STYLE_DISPLAY_TABLE_CAPTION;
|
|
|
|
|
if (isTableElement) {
|
|
|
|
|
return NS_STYLE_TOUCH_ACTION_AUTO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return disp->mTouchAction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
|
nsLayoutUtils::TransformToAncestorAndCombineRegions(
|
|
|
|
|
const nsRect& aBounds,
|
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
|
const nsIFrame* aAncestorFrame,
|
|
|
|
|
nsRegion* aPreciseTargetDest,
|
|
|
|
|
nsRegion* aImpreciseTargetDest)
|
|
|
|
|
{
|
|
|
|
|
if (aBounds.IsEmpty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Matrix4x4 matrix = GetTransformToAncestor(aFrame, aAncestorFrame);
|
|
|
|
|
Matrix matrix2D;
|
|
|
|
|
bool isPrecise = (matrix.Is2D(&matrix2D)
|
|
|
|
|
&& !matrix2D.HasNonAxisAlignedTransform());
|
|
|
|
|
nsRect transformed = TransformFrameRectToAncestor(
|
|
|
|
|
aFrame, aBounds, aAncestorFrame);
|
|
|
|
|
nsRegion* dest = isPrecise ? aPreciseTargetDest : aImpreciseTargetDest;
|
|
|
|
|
dest->OrWith(transformed);
|
|
|
|
|
}
|
2015-06-16 04:34:47 +03:00
|
|
|
|
|
|
|
|
|
/* static */ bool
|
|
|
|
|
nsLayoutUtils::ShouldUseNoScriptSheet(nsIDocument* aDocument)
|
|
|
|
|
{
|
|
|
|
|
// also handle the case where print is done from print preview
|
|
|
|
|
// see bug #342439 for more details
|
|
|
|
|
if (aDocument->IsStaticDocument()) {
|
|
|
|
|
aDocument = aDocument->GetOriginalDocument();
|
|
|
|
|
}
|
|
|
|
|
return aDocument->IsScriptEnabled();
|
|
|
|
|
}
|
2015-06-16 04:34:47 +03:00
|
|
|
|
|
|
|
|
|
/* static */ bool
|
|
|
|
|
nsLayoutUtils::ShouldUseNoFramesSheet(nsIDocument* aDocument)
|
|
|
|
|
{
|
|
|
|
|
bool allowSubframes = true;
|
|
|
|
|
nsIDocShell* docShell = aDocument->GetDocShell();
|
|
|
|
|
if (docShell) {
|
|
|
|
|
docShell->GetAllowSubframes(&allowSubframes);
|
|
|
|
|
}
|
|
|
|
|
return !allowSubframes;
|
|
|
|
|
}
|