Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/dom/DocumentLifecycle.h" | 32 #include "core/dom/DocumentLifecycle.h" |
| 33 | 33 |
| 34 #include "wtf/Assertions.h" | 34 #include "wtf/Assertions.h" |
| 35 #include <stdio.h> | 35 #include <stdio.h> |
| 36 | 36 |
| 37 namespace WebCore { | 37 namespace WebCore { |
| 38 | 38 |
| 39 static DocumentLifecycle::DeprecatedTransition* s_deprecatedTransitionStack = 0; | |
| 40 | |
| 41 DocumentLifecycle::Scope::Scope(DocumentLifecycle& lifecycle, State finalState) | |
| 42 : m_lifecycle(lifecycle) | |
| 43 , m_finalState(finalState) | |
| 44 { | |
| 45 } | |
| 46 | |
| 47 DocumentLifecycle::Scope::~Scope() | |
| 48 { | |
| 49 m_lifecycle.advanceTo(m_finalState); | |
| 50 } | |
| 51 | |
| 52 DocumentLifecycle::DeprecatedTransition::DeprecatedTransition(State from, State to) | |
| 53 : m_previous(s_deprecatedTransitionStack) | |
| 54 , m_from(from) | |
| 55 , m_to(to) | |
| 56 { | |
| 57 s_deprecatedTransitionStack = this; | |
| 58 } | |
| 59 | |
| 60 DocumentLifecycle::DeprecatedTransition::~DeprecatedTransition() | |
| 61 { | |
| 62 s_deprecatedTransitionStack = m_previous; | |
| 63 } | |
| 64 | |
| 39 DocumentLifecycle::DocumentLifecycle() | 65 DocumentLifecycle::DocumentLifecycle() |
| 40 : m_state(Uninitialized) | 66 : m_state(Uninitialized) |
| 41 { | 67 { |
| 42 } | 68 } |
| 43 | 69 |
| 44 DocumentLifecycle::~DocumentLifecycle() | 70 DocumentLifecycle::~DocumentLifecycle() |
| 45 { | 71 { |
| 46 } | 72 } |
| 47 | 73 |
| 74 #if !ASSERT_DISABLED | |
| 75 | |
| 48 bool DocumentLifecycle::canAdvanceTo(State state) const | 76 bool DocumentLifecycle::canAdvanceTo(State state) const |
| 49 { | 77 { |
| 78 // This transition is bogus, but we've whitelisted it anyway. | |
| 79 if (s_deprecatedTransitionStack && m_state == s_deprecatedTransitionStack->f rom() && state == s_deprecatedTransitionStack->to()) | |
| 80 return true; | |
| 50 if (state > m_state) | 81 if (state > m_state) |
| 51 return true; | 82 return true; |
| 52 // FIXME: We can dispose a document multiple times. This seems wrong. | 83 if (m_state == Disposed) { |
|
ojan
2014/02/07 02:08:46
Nit: should these if-statements be a switch statem
| |
| 53 // See https://code.google.com/p/chromium/issues/detail?id=301668. | 84 // FIXME: We can dispose a document multiple times. This seems wrong. |
| 54 if (m_state == Disposed) | 85 // See https://code.google.com/p/chromium/issues/detail?id=301668. |
| 55 return state == Disposed; | 86 return state == Disposed; |
| 56 if (m_state == Clean) { | 87 } |
| 57 // We can synchronously enter recalc style without rewinding to | 88 if (m_state == StyleClean) { |
| 58 // StyleRecalcPending. | 89 if (state == StyleRecalcPending) |
| 59 return state == InStyleRecalc; | 90 return true; |
| 91 // We can synchronously recalc style. | |
| 92 if (state == InStyleRecalc) | |
| 93 return true; | |
| 94 // We can synchronously perform layout. | |
| 95 if (state == InPreLayout) | |
| 96 return true; | |
| 97 if (state == InPerformLayout) | |
| 98 return true; | |
| 99 // We can redundant arrive in the style clean state. | |
|
ojan
2014/02/07 02:08:46
This is a little weird to me. I guess Document::re
abarth-chromium
2014/02/07 02:18:51
Yeah. It just doesn't do any work.
| |
| 100 if (state == StyleClean) | |
| 101 return true; | |
| 102 return false; | |
| 103 } | |
| 104 if (m_state == InPreLayout) { | |
| 105 if (state == InStyleRecalc) | |
| 106 return true; | |
| 107 if (state == StyleClean) | |
| 108 return true; | |
| 109 if (state == InPreLayout) | |
| 110 return true; | |
| 111 return false; | |
| 112 } | |
| 113 if (m_state == AfterPerformLayout) { | |
| 114 if (state == InPreLayout) | |
| 115 return true; | |
| 116 // If we're doing a partial layout, we won't actually end up cleaning | |
| 117 // out all the layout dirty bits. Instead, we'll return to StyleClean. | |
| 118 if (state == StyleClean) | |
| 119 return true; | |
| 120 return false; | |
| 121 } | |
| 122 if (m_state == LayoutClean) { | |
| 123 if (state == StyleRecalcPending) | |
| 124 return true; | |
| 125 // We can synchronously recalc style. | |
| 126 if (state == InStyleRecalc) | |
| 127 return true; | |
| 128 // We can synchronously perform layout. | |
| 129 if (state == InPreLayout) | |
| 130 return true; | |
| 131 if (state == InPerformLayout) | |
| 132 return true; | |
| 133 // We can redundant arrive in the layout clean state. | |
|
ojan
2014/02/07 02:08:46
Ditto...FrameView::layout doesn't early return eit
abarth-chromium
2014/02/07 02:18:51
It's because layout is recursive. As you walk up
| |
| 134 if (state == LayoutClean) | |
| 135 return true; | |
| 136 return false; | |
| 60 } | 137 } |
| 61 return false; | 138 return false; |
| 62 } | 139 } |
| 63 | 140 |
| 141 #endif | |
| 142 | |
| 64 void DocumentLifecycle::advanceTo(State state) | 143 void DocumentLifecycle::advanceTo(State state) |
| 65 { | 144 { |
| 66 ASSERT(canAdvanceTo(state)); | 145 ASSERT(canAdvanceTo(state)); |
| 67 m_state = state; | 146 m_state = state; |
| 68 } | 147 } |
| 69 | 148 |
| 70 void DocumentLifecycle::rewindTo(State state) | |
| 71 { | |
| 72 ASSERT(m_state == Clean); | |
| 73 ASSERT(state < m_state); | |
| 74 m_state = state; | |
| 75 ASSERT(isActive()); | |
| 76 } | 149 } |
| 77 | |
| 78 } | |
| OLD | NEW |