OLD | NEW |
---|---|
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()); | |
eae
2016/07/22 20:22:33
You probably want roundedLayoutSize(svg.getBBox().
| |
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 |
OLD | NEW |