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

Side by Side Diff: third_party/WebKit/Source/core/observer/ResizeObservation.cpp

Issue 2173203002: ResizeObserver pt3: observation computation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added missing CORE_EXPORT Created 4 years, 4 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/observer/ResizeObservation.h" 5 #include "core/observer/ResizeObservation.h"
6 6
7 #include "core/dom/Element.h" 7 #include "core/layout/LayoutBox.h"
8 #include "core/observer/ResizeObserver.h" 8 #include "core/observer/ResizeObserver.h"
9 #include "core/svg/SVGElement.h"
10 #include "core/svg/SVGGraphicsElement.h"
9 11
10 namespace blink { 12 namespace blink {
11 13
12 ResizeObservation::ResizeObservation(Element* target, ResizeObserver* observer) 14 ResizeObservation::ResizeObservation(Element* target, ResizeObserver* observer)
13 : m_target(target) 15 : m_target(target)
14 , m_observer(observer) 16 , m_observer(observer)
17 , m_observationSize(0, 0)
15 { 18 {
16 DCHECK(m_target); 19 DCHECK(m_target);
17 } 20 }
18 21
22 void ResizeObservation::setObservationSize(const LayoutSize& size)
23 {
24 m_observationSize = size;
25 }
26
27 bool ResizeObservation::observationSizeOutOfSync() const
28 {
29 return m_observationSize != ResizeObservation::getTargetSize(m_target);
30 }
31
32 size_t ResizeObservation::targetDepth()
33 {
34 unsigned depth = 0;
35 for (Element* parent = m_target; parent; parent = parent->parentElement())
36 ++depth;
37 return depth;
38 }
39
40 LayoutSize ResizeObservation::getTargetSize(Element* target) // static
41 {
42 if (target) {
43 if (target->isSVGElement() && toSVGElement(target)->isSVGGraphicsElement ()) {
44 SVGGraphicsElement& svg = toSVGGraphicsElement(*target);
45 return LayoutSize(svg.getBBox().size());
46 }
47 LayoutBox* layout = target->layoutBox();
48 if (layout)
49 return layout->contentSize();
50 }
51 return LayoutSize();
52 }
53
54
19 DEFINE_TRACE(ResizeObservation) 55 DEFINE_TRACE(ResizeObservation)
20 { 56 {
21 visitor->trace(m_target); 57 visitor->trace(m_target);
22 visitor->trace(m_observer); 58 visitor->trace(m_observer);
23 } 59 }
24 60
25 } // namespace blink 61 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/observer/ResizeObservation.h ('k') | third_party/WebKit/Source/core/observer/ResizeObserver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698