FIXED: Warning when closing a popover for the first time

Previously, the _CPPopoverWindow was trying to remove itself as observer while it wasn't defined
as an observer. This would cause a warning. This patch encapsulates addObserver and removeObserver into methods
that actually check if it's already observing/not observing when trying to observe/not observe
This commit is contained in:
Antoine Mercadal committed 2014-05-20 13:37:53 -07:00
1 parent f151920404
commit f953b4dc0f
1 file changed
+32 -5
+32 -5
View File
@@ -55,8 +55,9 @@ var _CPPopoverWindow_shouldClose_ = 1 << 4,
int _appearance @accessors(getter=appearance);
BOOL _isClosing @accessors(property=isClosing);
BOOL _closeOnBlur;
BOOL _browserAnimates;
BOOL _closeOnBlur;
BOOL _isObservingFrame;
BOOL _shouldPerformAnimation;
CPInteger _implementedDelegateMethods;
JSObject _orderOutTransitionFunction;
@@ -160,6 +161,32 @@ var _CPPopoverWindow_shouldClose_ = 1 << 4,
#pragma mark -
#pragma mark Observer
/*!
@ignore
Adds self as frame observer if not already observing it
*/
- (void)_addFrameObserver
{
if (_isObservingFrame)
return;
_isObservingFrame = YES;
[_targetView addObserver:self forKeyPath:@"frame" options:0 context:nil];
}
/*!
@ignore
Removes self as frame observer if already observing it
*/
- (void)_removeFrameObserver
{
if (!_isObservingFrame)
return;
_isObservingFrame = NO;
[_targetView removeObserver:self forKeyPath:@"frame"];
}
/*!
Update the _CPPopoverWindow frame if a resize event is observed.
*/
@@ -331,7 +358,7 @@ var _CPPopoverWindow_shouldClose_ = 1 << 4,
if (positioningView !== _targetView)
{
[[_targetView window] removeChildWindow:self];
[_targetView removeObserver:self forKeyPath:@"frame"];
[self _removeFrameObserver];
_targetView = positioningView;
}
@@ -521,14 +548,14 @@ var _CPPopoverWindow_shouldClose_ = 1 << 4,
- (void)_orderFront
{
if (![self isVisible])
[_targetView addObserver:self forKeyPath:@"frame" options:0 context:nil];
[self _addFrameObserver];
[super _orderFront];
}
- (void)_parentDidOrderInChild
{
[_targetView addObserver:self forKeyPath:@"frame" options:0 context:nil];
[self _addFrameObserver];
}
/*!
@@ -564,7 +591,7 @@ var _CPPopoverWindow_shouldClose_ = 1 << 4,
_DOMElement.removeEventListener(CPBrowserStyleProperty("transitionend"), _orderOutTransitionFunction, YES);
#endif
[_targetView removeObserver:self forKeyPath:@"frame"];
[self _removeFrameObserver];
[_parentWindow removeChildWindow:self];
[super _orderOutRecursively:recursive];