Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: Source/core/rendering/RenderView.h

Issue 196533012: Make LayoutState always be RAII (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Updated to ToT Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/rendering/RenderVTTCue.cpp ('k') | Source/core/rendering/RenderView.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2006 Apple Computer, Inc. 3 * Copyright (C) 2006 Apple Computer, Inc.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 || (renderer.isRenderBlock() && toRenderBlock(renderer).shapeInsideI nfo()) 219 || (renderer.isRenderBlock() && toRenderBlock(renderer).shapeInsideI nfo())
220 || (m_layoutState->shapeInsideInfo() && renderer.isRenderBlock() && !toRenderBlock(renderer).allowsShapeInsideInfoSharing(&m_layoutState->shapeInsid eInfo()->owner())) 220 || (m_layoutState->shapeInsideInfo() && renderer.isRenderBlock() && !toRenderBlock(renderer).allowsShapeInsideInfoSharing(&m_layoutState->shapeInsid eInfo()->owner()))
221 ) { 221 ) {
222 pushLayoutStateForCurrentFlowThread(renderer); 222 pushLayoutStateForCurrentFlowThread(renderer);
223 m_layoutState = new LayoutState(m_layoutState, renderer, offset, pag eHeight, pageHeightChanged, colInfo); 223 m_layoutState = new LayoutState(m_layoutState, renderer, offset, pag eHeight, pageHeightChanged, colInfo);
224 return true; 224 return true;
225 } 225 }
226 return false; 226 return false;
227 } 227 }
228 228
229 void layoutContent(const LayoutState&); 229 void layoutContent();
230 #ifndef NDEBUG 230 #ifndef NDEBUG
231 void checkLayoutState(const LayoutState&); 231 void checkLayoutState();
232 #endif 232 #endif
233 233
234 void positionDialog(RenderBox*); 234 void positionDialog(RenderBox*);
235 void positionDialogs(); 235 void positionDialogs();
236 236
237 void pushLayoutStateForCurrentFlowThread(const RenderObject&); 237 void pushLayoutStateForCurrentFlowThread(const RenderObject&);
238 void popLayoutStateForCurrentFlowThread(); 238 void popLayoutStateForCurrentFlowThread();
239 239
240 friend class LayoutStateMaintainer; 240 friend class LayoutStateMaintainer;
241 friend class LayoutStateDisabler; 241 friend class LayoutStateDisabler;
242 friend class RootLayoutStateScope;
242 243
243 bool shouldUsePrintingLayout() const; 244 bool shouldUsePrintingLayout() const;
244 245
245 FrameView* m_frameView; 246 FrameView* m_frameView;
246 247
247 RenderObject* m_selectionStart; 248 RenderObject* m_selectionStart;
248 RenderObject* m_selectionEnd; 249 RenderObject* m_selectionEnd;
249 250
250 int m_selectionStartPos; 251 int m_selectionStartPos;
251 int m_selectionEndPos; 252 int m_selectionEndPos;
252 253
253 LayoutUnit m_pageLogicalHeight; 254 LayoutUnit m_pageLogicalHeight;
254 bool m_pageLogicalHeightChanged; 255 bool m_pageLogicalHeightChanged;
255 LayoutState* m_layoutState; 256 LayoutState* m_layoutState;
256 unsigned m_layoutStateDisableCount; 257 unsigned m_layoutStateDisableCount;
257 OwnPtr<RenderLayerCompositor> m_compositor; 258 OwnPtr<RenderLayerCompositor> m_compositor;
258 OwnPtr<FlowThreadController> m_flowThreadController; 259 OwnPtr<FlowThreadController> m_flowThreadController;
259 RefPtr<IntervalArena> m_intervalArena; 260 RefPtr<IntervalArena> m_intervalArena;
260 261
261 RenderQuote* m_renderQuoteHead; 262 RenderQuote* m_renderQuoteHead;
262 unsigned m_renderCounterCount; 263 unsigned m_renderCounterCount;
263 }; 264 };
264 265
265 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderView, isRenderView()); 266 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderView, isRenderView());
266 267
268 class RootLayoutStateScope {
269 public:
270 explicit RootLayoutStateScope(RenderView& view)
271 : m_view(view)
272 {
273 ASSERT(!m_view.m_layoutState);
274 initializeLayoutState();
275 m_view.m_layoutState = &m_rootLayoutState;
276 }
277
278 ~RootLayoutStateScope()
279 {
280 ASSERT(m_view.m_layoutState == &m_rootLayoutState);
281 m_view.m_layoutState = 0;
282 }
283 private:
284 void initializeLayoutState();
285 RenderView& m_view;
286 LayoutState m_rootLayoutState;
287 };
288
267 // Stack-based class to assist with LayoutState push/pop 289 // Stack-based class to assist with LayoutState push/pop
268 class LayoutStateMaintainer { 290 class LayoutStateMaintainer {
269 WTF_MAKE_NONCOPYABLE(LayoutStateMaintainer); 291 WTF_MAKE_NONCOPYABLE(LayoutStateMaintainer);
270 public: 292 public:
271 // ctor to push now 293 // ctor to push now
272 explicit LayoutStateMaintainer(RenderBox& root, const LayoutSize& offset, La youtUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0 ) 294 explicit LayoutStateMaintainer(RenderBox& root, const LayoutSize& offset, La youtUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0 )
273 : m_view(*root.view()) 295 : m_view(*root.view())
274 , m_disabled(root.shouldDisableLayoutState()) 296 , m_disabled(root.shouldDisableLayoutState())
275 , m_didStart(false) 297 , m_didStart(false)
276 , m_didEnd(false) 298 , m_didEnd(false)
277 , m_didCreateLayoutState(false) 299 , m_didCreateLayoutState(false)
278 { 300 {
279 push(root, offset, pageHeight, pageHeightChanged, colInfo); 301 push(root, offset, pageHeight, pageHeightChanged, colInfo);
280 } 302 }
281 303
282 // ctor to maybe push later 304 // ctor to maybe push later
283 explicit LayoutStateMaintainer(RenderBox& root) 305 explicit LayoutStateMaintainer(RenderBox& root)
284 : m_view(*root.view()) 306 : m_view(*root.view())
285 , m_disabled(false) 307 , m_disabled(false)
286 , m_didStart(false) 308 , m_didStart(false)
287 , m_didEnd(false) 309 , m_didEnd(false)
288 , m_didCreateLayoutState(false) 310 , m_didCreateLayoutState(false)
289 { 311 {
290 } 312 }
291 313
292 ~LayoutStateMaintainer() 314 ~LayoutStateMaintainer()
293 { 315 {
316 if (m_didStart)
317 pop();
294 ASSERT(m_didStart == m_didEnd); // if this fires, it means that someon e did a push(), but forgot to pop(). 318 ASSERT(m_didStart == m_didEnd); // if this fires, it means that someon e did a push(), but forgot to pop().
295 } 319 }
296 320
297 void push(RenderBox& root, const LayoutSize& offset, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0) 321 void push(RenderBox& root, const LayoutSize& offset, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
298 { 322 {
299 ASSERT(!m_didStart); 323 ASSERT(!m_didStart);
300 // We push state even if disabled, because we still need to store layout Delta 324 // We push state even if disabled, because we still need to store layout Delta
301 m_didCreateLayoutState = m_view.pushLayoutState(root, offset, pageHeight , pageHeightChanged, colInfo); 325 m_didCreateLayoutState = m_view.pushLayoutState(root, offset, pageHeight , pageHeightChanged, colInfo);
302 if (m_disabled && m_didCreateLayoutState) 326 if (m_disabled && m_didCreateLayoutState)
303 m_view.disableLayoutState(); 327 m_view.disableLayoutState();
304 m_didStart = true; 328 m_didStart = true;
305 } 329 }
306 330
307 void pop()
308 {
309 if (m_didStart) {
310 ASSERT(!m_didEnd);
311 if (m_didCreateLayoutState) {
312 m_view.popLayoutState();
313 if (m_disabled)
314 m_view.enableLayoutState();
315 }
316
317 m_didEnd = true;
318 }
319 }
320
321 bool didPush() const { return m_didStart; } 331 bool didPush() const { return m_didStart; }
322 332
323 private: 333 private:
334 void pop()
335 {
336 ASSERT(m_didStart && !m_didEnd);
337 if (m_didCreateLayoutState) {
338 m_view.popLayoutState();
339 if (m_disabled)
340 m_view.enableLayoutState();
341 }
342
343 m_didEnd = true;
344 }
345
324 RenderView& m_view; 346 RenderView& m_view;
325 bool m_disabled : 1; // true if the offset and clip part of layoutSta te is disabled 347 bool m_disabled : 1; // true if the offset and clip part of layoutSta te is disabled
326 bool m_didStart : 1; // true if we did a push or disable 348 bool m_didStart : 1; // true if we did a push or disable
327 bool m_didEnd : 1; // true if we popped or re-enabled 349 bool m_didEnd : 1; // true if we popped or re-enabled
328 bool m_didCreateLayoutState : 1; // true if we actually made a layout state. 350 bool m_didCreateLayoutState : 1; // true if we actually made a layout state.
329 }; 351 };
330 352
331 class LayoutStateDisabler { 353 class LayoutStateDisabler {
332 WTF_MAKE_NONCOPYABLE(LayoutStateDisabler); 354 WTF_MAKE_NONCOPYABLE(LayoutStateDisabler);
333 public: 355 public:
334 LayoutStateDisabler(const RenderBox& root) 356 LayoutStateDisabler(const RenderBox& root)
335 : m_view(*root.view()) 357 : m_view(*root.view())
336 { 358 {
337 m_view.disableLayoutState(); 359 m_view.disableLayoutState();
338 } 360 }
339 361
340 ~LayoutStateDisabler() 362 ~LayoutStateDisabler()
341 { 363 {
342 m_view.enableLayoutState(); 364 m_view.enableLayoutState();
343 } 365 }
344 private: 366 private:
345 RenderView& m_view; 367 RenderView& m_view;
346 }; 368 };
347 369
348 } // namespace WebCore 370 } // namespace WebCore
349 371
350 #endif // RenderView_h 372 #endif // RenderView_h
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderVTTCue.cpp ('k') | Source/core/rendering/RenderView.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698