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

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

Issue 2188983003: ResizeObserver pt5: size change notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: All CR comments addressed 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/layout/LayoutBox.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" 9 #include "core/svg/SVGElement.h"
10 #include "core/svg/SVGGraphicsElement.h" 10 #include "core/svg/SVGGraphicsElement.h"
11 11
12 namespace blink { 12 namespace blink {
13 13
14 ResizeObservation::ResizeObservation(Element* target, ResizeObserver* observer) 14 ResizeObservation::ResizeObservation(Element* target, ResizeObserver* observer)
15 : m_target(target) 15 : m_target(target)
16 , m_observer(observer) 16 , m_observer(observer)
17 , m_observationSize(0, 0) 17 , m_observationSize(0, 0)
18 , m_elementSizeChanged(true)
18 { 19 {
19 DCHECK(m_target); 20 DCHECK(m_target);
21 m_observer->elementSizeChanged();
20 } 22 }
21 23
22 void ResizeObservation::setObservationSize(const LayoutSize& size) 24 void ResizeObservation::setObservationSize(const LayoutSize& size)
23 { 25 {
24 m_observationSize = size; 26 m_observationSize = size;
27 m_elementSizeChanged = false;
25 } 28 }
26 29
27 bool ResizeObservation::observationSizeOutOfSync() const 30 bool ResizeObservation::observationSizeOutOfSync() const
28 { 31 {
29 return m_observationSize != ResizeObservation::getTargetSize(m_target); 32 return m_elementSizeChanged && m_observationSize != ResizeObservation::getTa rgetSize(m_target);
30 } 33 }
31 34
32 size_t ResizeObservation::targetDepth() 35 size_t ResizeObservation::targetDepth()
33 { 36 {
34 unsigned depth = 0; 37 unsigned depth = 0;
35 for (Element* parent = m_target; parent; parent = parent->parentElement()) 38 for (Element* parent = m_target; parent; parent = parent->parentElement())
36 ++depth; 39 ++depth;
37 return depth; 40 return depth;
38 } 41 }
39 42
40 LayoutSize ResizeObservation::getTargetSize(Element* target) // static 43 LayoutSize ResizeObservation::getTargetSize(Element* target) // static
41 { 44 {
42 if (target) { 45 if (target) {
43 if (target->isSVGElement() && toSVGElement(target)->isSVGGraphicsElement ()) { 46 if (target->isSVGElement() && toSVGElement(target)->isSVGGraphicsElement ()) {
44 SVGGraphicsElement& svg = toSVGGraphicsElement(*target); 47 SVGGraphicsElement& svg = toSVGGraphicsElement(*target);
45 return LayoutSize(svg.getBBox().size()); 48 return LayoutSize(svg.getBBox().size());
46 } 49 }
47 LayoutBox* layout = target->layoutBox(); 50 LayoutBox* layout = target->layoutBox();
48 if (layout) 51 if (layout)
49 return layout->contentSize(); 52 return layout->contentSize();
50 } 53 }
51 return LayoutSize(); 54 return LayoutSize();
52 } 55 }
53 56
57 void ResizeObservation::elementSizeChanged()
58 {
59 m_elementSizeChanged = true;
60 m_observer->elementSizeChanged();
61 }
54 62
55 DEFINE_TRACE(ResizeObservation) 63 DEFINE_TRACE(ResizeObservation)
56 { 64 {
57 visitor->trace(m_target); 65 visitor->trace(m_target);
58 visitor->trace(m_observer); 66 visitor->trace(m_observer);
59 } 67 }
60 68
61 } // namespace blink 69 } // 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