Bug 1350671 - stylo: Allow resolving out of date styles when explicitly reconstructing frames for an element. r=bholley

MozReview-Commit-ID: A7ssy7ygWLh

--HG--
extra : rebase_source : 7f8fa109f1a739b68525e3ff662024267189d93f
This commit is contained in:
Cameron McCormack 2017-03-28 13:46:59 +08:00
Родитель 0e5b3d1e8c
Коммит e945f00cd0
6 изменённых файлов: 45 добавлений и 6 удалений

Просмотреть файл

@ -2953,6 +2953,10 @@ PresShell::RecreateFramesFor(nsIContent* aContent)
nsStyleChangeList changeList(mPresContext->StyleSet()->BackendType());
changeList.AppendChange(nullptr, aContent, nsChangeHint_ReconstructFrame);
// We might have restyles pending when we're asked to recreate frames.
// Record that we're OK with stale styles being returned, to avoid assertions.
ServoStyleSet::AutoAllowStaleStyles guard(mStyleSet->GetAsServo());
// Mark ourselves as not safe to flush while we're doing frame construction.
++mChangeNestCount;
RestyleManager* restyleManager = mPresContext->RestyleManager();

Просмотреть файл

@ -291,7 +291,8 @@ SERVO_BINDING_FUNC(Servo_NoteExplicitHints, void, RawGeckoElementBorrowed elemen
SERVO_BINDING_FUNC(Servo_TakeChangeHint, nsChangeHint, RawGeckoElementBorrowed element)
SERVO_BINDING_FUNC(Servo_ResolveStyle, ServoComputedValuesStrong,
RawGeckoElementBorrowed element,
RawServoStyleSetBorrowed set)
RawServoStyleSetBorrowed set,
bool allow_stale)
SERVO_BINDING_FUNC(Servo_ResolvePseudoStyle, ServoComputedValuesStrong,
RawGeckoElementBorrowed element, nsIAtom* pseudo_tag,
bool is_probe, RawServoStyleSetBorrowed set)

Просмотреть файл

@ -27,6 +27,7 @@ using namespace mozilla::dom;
ServoStyleSet::ServoStyleSet()
: mPresContext(nullptr)
, mBatching(0)
, mAllowResolveStaleStyles(false)
{
}
@ -783,7 +784,8 @@ ServoStyleSet::RebuildData()
already_AddRefed<ServoComputedValues>
ServoStyleSet::ResolveServoStyle(Element* aElement)
{
return Servo_ResolveStyle(aElement, mRawSet.get()).Consume();
return Servo_ResolveStyle(aElement, mRawSet.get(),
mAllowResolveStaleStyles).Consume();
}
void

Просмотреть файл

@ -46,6 +46,29 @@ class ServoStyleSet
{
friend class ServoRestyleManager;
public:
class AutoAllowStaleStyles
{
public:
AutoAllowStaleStyles(ServoStyleSet* aStyleSet)
: mStyleSet(aStyleSet)
{
if (mStyleSet) {
MOZ_ASSERT(!mStyleSet->mAllowResolveStaleStyles);
mStyleSet->mAllowResolveStaleStyles = true;
}
}
~AutoAllowStaleStyles()
{
if (mStyleSet) {
mStyleSet->mAllowResolveStaleStyles = false;
}
}
private:
ServoStyleSet* mStyleSet;
};
static bool IsInServoTraversal()
{
// The callers of this function are generally main-thread-only _except_
@ -296,6 +319,7 @@ private:
EnumeratedArray<SheetType, SheetType::Count,
nsTArray<RefPtr<ServoStyleSheet>>> mSheets;
int32_t mBatching;
bool mAllowResolveStaleStyles;
// Stores pointers to our cached style contexts for non-inheriting anonymous
// boxes.

Просмотреть файл

@ -1812,7 +1812,8 @@ extern "C" {
}
extern "C" {
pub fn Servo_ResolveStyle(element: RawGeckoElementBorrowed,
set: RawServoStyleSetBorrowed)
set: RawServoStyleSetBorrowed,
allow_stale: bool)
-> ServoComputedValuesStrong;
}
extern "C" {

Просмотреть файл

@ -1473,15 +1473,22 @@ pub extern "C" fn Servo_TakeChangeHint(element: RawGeckoElementBorrowed) -> nsCh
#[no_mangle]
pub extern "C" fn Servo_ResolveStyle(element: RawGeckoElementBorrowed,
raw_data: RawServoStyleSetBorrowed)
raw_data: RawServoStyleSetBorrowed,
allow_stale: bool)
-> ServoComputedValuesStrong
{
let element = GeckoElement(element);
debug!("Servo_ResolveStyle: {:?}", element);
let data = unsafe { element.ensure_data() }.borrow_mut();
if !data.has_current_styles() {
warn!("Resolving style on unstyled element with lazy computation forbidden.");
let valid_styles = if allow_stale {
data.has_styles()
} else {
data.has_current_styles()
};
if !valid_styles {
warn!("Resolving style on element without current styles with lazy computation forbidden.");
let per_doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow();
return per_doc_data.default_computed_values().clone().into_strong();
}