Bug 1070710 - Add mozilla::ViewRegion which assembles a LayoutDeviceIntRegion as NSViews, and use it for vibrancy and window dragging. r=spohl, a=gchang
authorMarkus Stange <mstange@themasta.com>
Tue, 02 Aug 2016 15:48:31 -0400
changeset 342259 1a9c61ffe9ab93d718d6cc19b93aac69a8275775
parent 342258 adadc9dbb64824d48696e956c37635dd70e2e454
child 342260 4e5e1d4c6b048072e16880097b7a29a5c8741c91
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersspohl, gchang
bugs1070710
milestone49.0
Bug 1070710 - Add mozilla::ViewRegion which assembles a LayoutDeviceIntRegion as NSViews, and use it for vibrancy and window dragging. r=spohl, a=gchang
widget/cocoa/VibrancyManager.h
widget/cocoa/VibrancyManager.mm
widget/cocoa/ViewRegion.h
widget/cocoa/ViewRegion.mm
widget/cocoa/moz.build
widget/cocoa/nsChildView.h
widget/cocoa/nsChildView.mm
widget/cocoa/nsDeviceContextSpecX.mm
widget/cocoa/nsScreenCocoa.mm
--- a/widget/cocoa/VibrancyManager.h
+++ b/widget/cocoa/VibrancyManager.h
@@ -6,16 +6,17 @@
 
 #ifndef VibrancyManager_h
 #define VibrancyManager_h
 
 #include "mozilla/Assertions.h"
 #include "nsClassHashtable.h"
 #include "nsRegion.h"
 #include "nsTArray.h"
+#include "ViewRegion.h"
 
 #import <Foundation/NSGeometry.h>
 
 @class NSColor;
 @class NSView;
 class nsChildView;
 
 namespace mozilla {
@@ -96,27 +97,20 @@ public:
 
   /**
    * Check whether the operating system supports vibrancy at all.
    * You may only create a VibrancyManager instance if this returns true.
    * @return Whether VibrancyManager can be used on this OS.
    */
   static bool SystemSupportsVibrancy();
 
-  // The following are only public because otherwise ClearVibrantRegionFunc
-  // can't see them.
-  struct VibrantRegion {
-    LayoutDeviceIntRegion region;
-    nsTArray<NSView*> effectViews;
-  };
-  void ClearVibrantRegion(const VibrantRegion& aVibrantRegion) const;
-
 protected:
-  NSView* CreateEffectView(VibrancyType aType, NSRect aRect);
+  void ClearVibrantRegion(const LayoutDeviceIntRegion& aVibrantRegion) const;
+  NSView* CreateEffectView(VibrancyType aType);
 
   const nsChildView& mCoordinateConverter;
   NSView* mContainerView;
-  nsClassHashtable<nsUint32HashKey, VibrantRegion> mVibrantRegions;
+  nsClassHashtable<nsUint32HashKey, ViewRegion> mVibrantRegions;
 };
 
 } // namespace mozilla
 
 #endif // VibrancyManager_h
--- a/widget/cocoa/VibrancyManager.mm
+++ b/widget/cocoa/VibrancyManager.mm
@@ -10,75 +10,35 @@
 
 using namespace mozilla;
 
 void
 VibrancyManager::UpdateVibrantRegion(VibrancyType aType,
                                      const LayoutDeviceIntRegion& aRegion)
 {
   auto& vr = *mVibrantRegions.LookupOrAdd(uint32_t(aType));
-  if (vr.region == aRegion) {
-    return;
-  }
-
-  // We need to construct the required region using as many EffectViews
-  // as necessary. We try to update the geometry of existing views if
-  // possible, or create new ones or remove old ones if the number of
-  // rects in the region has changed.
-
-  nsTArray<NSView*> viewsToRecycle;
-  vr.effectViews.SwapElements(viewsToRecycle);
-  // vr.effectViews is now empty.
-
-  size_t i = 0;
-  for (auto iter = aRegion.RectIter();
-       !iter.Done() || i < viewsToRecycle.Length();
-       i++) {
-    if (!iter.Done()) {
-      NSView* view = nil;
-      NSRect rect = mCoordinateConverter.DevPixelsToCocoaPoints(iter.Get());
-      if (i < viewsToRecycle.Length()) {
-        view = viewsToRecycle[i];
-        [view setFrame:rect];
-        [view setNeedsDisplay:YES];
-      } else {
-        view = CreateEffectView(aType, rect);
-        [mContainerView addSubview:view];
-
-        // Now that the view is in the view hierarchy, it'll be kept alive by
-        // its superview, so we can drop our reference.
-        [view release];
-      }
-      vr.effectViews.AppendElement(view);
-      iter.Next();
-    } else {
-      // Our new region is made of less rects than the old region, so we can
-      // remove this view. We only have a weak reference to it, so removing it
-      // from the view hierarchy will release it.
-      [viewsToRecycle[i] removeFromSuperview];
-    }
-  }
-
-  vr.region = aRegion;
+  vr.UpdateRegion(aRegion, mCoordinateConverter, mContainerView, ^() {
+    return this->CreateEffectView(aType);
+  });
 }
 
 void
 VibrancyManager::ClearVibrantAreas() const
 {
   for (auto iter = mVibrantRegions.ConstIter(); !iter.Done(); iter.Next()) {
-    ClearVibrantRegion(*iter.UserData());
+    ClearVibrantRegion(iter.UserData()->Region());
   }
 }
 
 void
-VibrancyManager::ClearVibrantRegion(const VibrantRegion& aVibrantRegion) const
+VibrancyManager::ClearVibrantRegion(const LayoutDeviceIntRegion& aVibrantRegion) const
 {
   [[NSColor clearColor] set];
 
-  for (auto iter = aVibrantRegion.region.RectIter(); !iter.Done(); iter.Next()) {
+  for (auto iter = aVibrantRegion.RectIter(); !iter.Done(); iter.Next()) {
     NSRectFill(mCoordinateConverter.DevPixelsToCocoaPoints(iter.Get()));
   }
 }
 
 @interface NSView(CurrentFillColor)
 - (NSColor*)_currentFillColor;
 @end
 
@@ -93,42 +53,38 @@ AdjustedColor(NSColor* aFillColor, Vibra
     return [NSColor colorWithDeviceWhite:0.96 alpha:1.0];
   }
   return aFillColor;
 }
 
 NSColor*
 VibrancyManager::VibrancyFillColorForType(VibrancyType aType)
 {
-  const nsTArray<NSView*>& views =
-    mVibrantRegions.LookupOrAdd(uint32_t(aType))->effectViews;
+  NSView* view = mVibrantRegions.LookupOrAdd(uint32_t(aType))->GetAnyView();
 
-  if (!views.IsEmpty() &&
-      [views[0] respondsToSelector:@selector(_currentFillColor)]) {
+  if (view && [view respondsToSelector:@selector(_currentFillColor)]) {
     // -[NSVisualEffectView _currentFillColor] is the color that our view
     // would draw during its drawRect implementation, if we hadn't
     // disabled that.
-    return AdjustedColor([views[0] _currentFillColor], aType);
+    return AdjustedColor([view _currentFillColor], aType);
   }
   return [NSColor whiteColor];
 }
 
 @interface NSView(FontSmoothingBackgroundColor)
 - (NSColor*)fontSmoothingBackgroundColor;
 @end
 
 NSColor*
 VibrancyManager::VibrancyFontSmoothingBackgroundColorForType(VibrancyType aType)
 {
-  const nsTArray<NSView*>& views =
-    mVibrantRegions.LookupOrAdd(uint32_t(aType))->effectViews;
+  NSView* view = mVibrantRegions.LookupOrAdd(uint32_t(aType))->GetAnyView();
 
-  if (!views.IsEmpty() &&
-      [views[0] respondsToSelector:@selector(fontSmoothingBackgroundColor)]) {
-    return [views[0] fontSmoothingBackgroundColor];
+  if (view && [view respondsToSelector:@selector(fontSmoothingBackgroundColor)]) {
+    return [view fontSmoothingBackgroundColor];
   }
   return [NSColor clearColor];
 }
 
 static void
 DrawRectNothing(id self, SEL _cmd, NSRect aRect)
 {
   // The super implementation would clear the background.
@@ -248,24 +204,24 @@ enum {
 
 @interface NSView(NSVisualEffectViewMethods)
 - (void)setState:(NSUInteger)state;
 - (void)setMaterial:(NSUInteger)material;
 - (void)setEmphasized:(BOOL)emphasized;
 @end
 
 NSView*
-VibrancyManager::CreateEffectView(VibrancyType aType, NSRect aRect)
+VibrancyManager::CreateEffectView(VibrancyType aType)
 {
   static Class EffectViewClassWithoutForegroundVibrancy = CreateEffectViewClass(NO);
   static Class EffectViewClassWithForegroundVibrancy = CreateEffectViewClass(YES);
 
   Class EffectViewClass = HasVibrantForeground(aType)
     ? EffectViewClassWithForegroundVibrancy : EffectViewClassWithoutForegroundVibrancy;
-  NSView* effectView = [[EffectViewClass alloc] initWithFrame:aRect];
+  NSView* effectView = [[EffectViewClass alloc] initWithFrame:NSZeroRect];
   [effectView performSelector:@selector(setAppearance:)
                    withObject:AppearanceForVibrancyType(aType)];
   [effectView setState:VisualEffectStateForVibrancyType(aType)];
 
   BOOL canUseElCapitanMaterials = nsCocoaFeatures::OnElCapitanOrLater();
   if (aType == VibrancyType::MENU) {
     // Before 10.11 there is no material that perfectly matches the menu
     // look. Of all available material types, NSVisualEffectMaterialTitlebar
new file mode 100644
--- /dev/null
+++ b/widget/cocoa/ViewRegion.h
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef ViewRegion_h
+#define ViewRegion_h
+
+#include "Units.h"
+#include "nsTArray.h"
+
+@class NSView;
+
+namespace mozilla {
+
+/**
+ * Manages a set of NSViews to cover a LayoutDeviceIntRegion.
+ */
+class ViewRegion {
+public:
+  ~ViewRegion();
+
+  mozilla::LayoutDeviceIntRegion Region() { return mRegion; }
+
+  /**
+   * Update the region.
+   * @param aRegion  The new region.
+   * @param aCoordinateConverter  The nsChildView to use for converting
+   *   LayoutDeviceIntRect device pixel coordinates into Cocoa NSRect coordinates.
+   * @param aContainerView  The view that's going to be the superview of the
+   *   NSViews which will be created for this region.
+   * @param aViewCreationCallback  A block that instantiates new NSViews.
+   * @return  Whether or not the region changed.
+   */
+  bool UpdateRegion(const mozilla::LayoutDeviceIntRegion& aRegion,
+                    const nsChildView& aCoordinateConverter,
+                    NSView* aContainerView,
+                    NSView* (^aViewCreationCallback)());
+
+  /**
+   * Return an NSView from the region, if there is any.
+   */
+  NSView* GetAnyView() { return mViews.Length() > 0 ? mViews[0] : nil; }
+
+private:
+  mozilla::LayoutDeviceIntRegion mRegion;
+  nsTArray<NSView*> mViews;
+};
+
+} // namespace mozilla
+
+#endif // ViewRegion_h
new file mode 100644
--- /dev/null
+++ b/widget/cocoa/ViewRegion.mm
@@ -0,0 +1,71 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "ViewRegion.h"
+#import <Cocoa/Cocoa.h>
+
+using namespace mozilla;
+
+ViewRegion::~ViewRegion()
+{
+  for (size_t i = 0; i < mViews.Length(); i++) {
+    [mViews[i] removeFromSuperview];
+  }
+}
+
+bool
+ViewRegion::UpdateRegion(const LayoutDeviceIntRegion& aRegion,
+                         const nsChildView& aCoordinateConverter,
+                         NSView* aContainerView,
+                         NSView* (^aViewCreationCallback)())
+{
+  if (mRegion == aRegion) {
+    return false;
+  }
+
+  // We need to construct the required region using as many EffectViews
+  // as necessary. We try to update the geometry of existing views if
+  // possible, or create new ones or remove old ones if the number of
+  // rects in the region has changed.
+
+  nsTArray<NSView*> viewsToRecycle;
+  mViews.SwapElements(viewsToRecycle);
+  // The mViews array is now empty.
+
+  size_t i = 0;
+  for (auto iter = aRegion.RectIter();
+       !iter.Done() || i < viewsToRecycle.Length();
+       i++) {
+    if (!iter.Done()) {
+      NSView* view = nil;
+      NSRect rect = aCoordinateConverter.DevPixelsToCocoaPoints(iter.Get());
+      if (i < viewsToRecycle.Length()) {
+        view = viewsToRecycle[i];
+      } else {
+        view = aViewCreationCallback();
+        [aContainerView addSubview:view];
+
+        // Now that the view is in the view hierarchy, it'll be kept alive by
+        // its superview, so we can drop our reference.
+        [view release];
+      }
+      if (!NSEqualRects(rect, [view frame])) {
+        [view setFrame:rect];
+      }
+      [view setNeedsDisplay:YES];
+      mViews.AppendElement(view);
+      iter.Next();
+    } else {
+      // Our new region is made of fewer rects than the old region, so we can
+      // remove this view. We only have a weak reference to it, so removing it
+      // from the view hierarchy will release it.
+      [viewsToRecycle[i] removeFromSuperview];
+    }
+  }
+
+  mRegion = aRegion;
+  return true;
+}
--- a/widget/cocoa/moz.build
+++ b/widget/cocoa/moz.build
@@ -53,16 +53,17 @@ UNIFIED_SOURCES += [
     'nsSystemStatusBarCocoa.mm',
     'nsToolkit.mm',
     'nsWidgetFactory.mm',
     'nsWindowMap.mm',
     'OSXNotificationCenter.mm',
     'SwipeTracker.mm',
     'TextInputHandler.mm',
     'VibrancyManager.mm',
+    'ViewRegion.mm',
     'WidgetTraceEvent.mm',
 ]
 
 # These files cannot be built in unified mode because they cause symbol conflicts
 SOURCES += [
     'nsChildView.mm',
     'nsClipboard.mm',
     'nsCocoaDebugUtils.mm',
--- a/widget/cocoa/nsChildView.h
+++ b/widget/cocoa/nsChildView.h
@@ -23,16 +23,17 @@
 #include "GLContextTypes.h"
 #include "mozilla/Mutex.h"
 #include "nsRegion.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/UniquePtr.h"
 
 #include "nsString.h"
 #include "nsIDragService.h"
+#include "ViewRegion.h"
 
 #import <Carbon/Carbon.h>
 #import <Cocoa/Cocoa.h>
 #import <AppKit/NSOpenGL.h>
 
 class nsChildView;
 class nsCocoaWindow;
 
@@ -499,17 +500,17 @@ public:
   virtual bool PreRender(LayerManagerComposite* aManager) override;
   virtual void PostRender(LayerManagerComposite* aManager) override;
   virtual void DrawWindowOverlay(LayerManagerComposite* aManager,
                                  LayoutDeviceIntRect aRect) override;
 
   virtual void UpdateThemeGeometries(const nsTArray<ThemeGeometry>& aThemeGeometries) override;
 
   virtual void UpdateWindowDraggingRegion(const LayoutDeviceIntRegion& aRegion) override;
-  const LayoutDeviceIntRegion& GetDraggableRegion() { return mDraggableRegion; }
+  LayoutDeviceIntRegion GetNonDraggableRegion() { return mNonDraggableRegion.Region(); }
 
   virtual void ReportSwipeStarted(uint64_t aInputBlockId, bool aStartSwipe) override;
 
   virtual void LookUpDictionary(
                  const nsAString& aText,
                  const nsTArray<mozilla::FontRange>& aFontRangeArray,
                  const bool aIsVertical,
                  const LayoutDeviceIntPoint& aPoint) override;
@@ -665,17 +666,17 @@ protected:
   mozilla::UniquePtr<RectTextureImage> mCornerMaskImage;
   mozilla::UniquePtr<RectTextureImage> mTitlebarImage;
   mozilla::UniquePtr<RectTextureImage> mBasicCompositorImage;
 
   // The area of mTitlebarCGContext that has changed and needs to be
   // uploaded to to mTitlebarImage. Main thread only.
   nsIntRegion           mDirtyTitlebarRegion;
 
-  LayoutDeviceIntRegion mDraggableRegion;
+  mozilla::ViewRegion   mNonDraggableRegion;
 
   // Cached value of [mView backingScaleFactor], to avoid sending two obj-c
   // messages (respondsToSelector, backingScaleFactor) every time we need to
   // use it.
   // ** We'll need to reinitialize this if the backing resolution changes. **
   mutable CGFloat       mBackingScaleFactor;
 
   bool                  mVisible;
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -2783,22 +2783,51 @@ nsChildView::DoRemoteComposition(const L
   // anything during the basic compositor transaction. Draw the overlay now.
   DrawWindowOverlay(mGLPresenter, aRenderRect);
 
   mGLPresenter->EndFrame();
 
   [(ChildView*)mView postRender:mGLPresenter->GetNSOpenGLContext()];
 }
 
+@interface NonDraggableView : NSView
+@end
+
+@implementation NonDraggableView
+- (BOOL)mouseDownCanMoveWindow { return NO; }
+- (NSView*)hitTest:(NSPoint)aPoint { return nil; }
+@end
+
 void
 nsChildView::UpdateWindowDraggingRegion(const LayoutDeviceIntRegion& aRegion)
 {
-  if (mDraggableRegion != aRegion) {
-    mDraggableRegion = aRegion;
-    [(ChildView*)mView updateWindowDraggableState];
+  // mView returns YES from mouseDownCanMoveWindow, so we need to put NSViews
+  // that return NO from mouseDownCanMoveWindow in the places that shouldn't
+  // be draggable. We can't do it the other way round because returning
+  // YES from mouseDownCanMoveWindow doesn't have any effect if there's a
+  // superview that returns NO.
+  LayoutDeviceIntRegion nonDraggable;
+  nonDraggable.Sub(LayoutDeviceIntRect(0, 0, mBounds.width, mBounds.height), aRegion);
+
+  __block bool changed = false;
+
+  // Suppress calls to setNeedsDisplay during NSView geometry changes.
+  ManipulateViewWithoutNeedingDisplay(mView, ^() {
+    changed = mNonDraggableRegion.UpdateRegion(nonDraggable, *this, mView, ^() {
+      return [[NonDraggableView alloc] initWithFrame:NSZeroRect];
+    });
+  });
+
+  if (changed) {
+    // Trigger an update to the window server. This will call
+    // mouseDownCanMoveWindow.
+    // Doing this manually is only necessary because we're suppressing
+    // setNeedsDisplay calls above.
+    [[mView window] setMovableByWindowBackground:NO];
+    [[mView window] setMovableByWindowBackground:YES];
   }
 }
 
 void
 nsChildView::ReportSwipeStarted(uint64_t aInputBlockId,
                                 bool aStartSwipe)
 {
   if (mSwipeEventQueue && mSwipeEventQueue->inputBlockId == aInputBlockId) {
@@ -3710,18 +3739,20 @@ NSEvent* gLastDragMouseDownEvent = nil;
   }
   [super scrollRect:aRect by:offset];
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 - (BOOL)mouseDownCanMoveWindow
 {
-  // Return YES so that _regionForOpaqueDescendants gets called, where the
-  // actual draggable region will be assembled.
+  // Return YES so that parts of this view can be draggable. The non-draggable
+  // parts will be covered by NSViews that return NO from
+  // mouseDownCanMoveWindow and thus override draggability from the inside.
+  // These views are assembled in nsChildView::UpdateWindowDraggingRegion.
   return YES;
 }
 
 -(void)updateGLContext
 {
   [mGLContext setView:self];
   [mGLContext update];
 }
@@ -4683,17 +4714,17 @@ NSEvent* gLastDragMouseDownEvent = nil;
   // This might destroy our widget (and null out mGeckoChild).
   bool defaultPrevented =
     (mGeckoChild->DispatchInputEvent(&geckoEvent) == nsEventStatus_eConsumeNoDefault);
 
   // Check to see if we are double-clicking in the titlebar.
   CGFloat locationInTitlebar = [[self window] frame].size.height - [theEvent locationInWindow].y;
   LayoutDeviceIntPoint pos = geckoEvent.mRefPoint;
   if (!defaultPrevented && [theEvent clickCount] == 2 &&
-      mGeckoChild->GetDraggableRegion().Contains(pos.x, pos.y) &&
+      !mGeckoChild->GetNonDraggableRegion().Contains(pos.x, pos.y) &&
       [[self window] isKindOfClass:[ToolbarWindow class]] &&
       (locationInTitlebar < [(ToolbarWindow*)[self window] titlebarHeight] ||
        locationInTitlebar < [(ToolbarWindow*)[self window] unifiedToolbarHeight])) {
     if ([self shouldZoomOnDoubleClick]) {
       [[self window] performZoom:nil];
     } else if ([self shouldMinimizeOnTitlebarDoubleClick]) {
       NSButton *minimizeButton = [[self window] standardWindowButton:NSWindowMiniaturizeButton];
       [minimizeButton performClick:self];
@@ -4718,85 +4749,16 @@ NSEvent* gLastDragMouseDownEvent = nil;
   event.mRefPoint = mGeckoChild->CocoaPointsToDevPixels(localEventLocation);
 
   event.mExitFrom = aExitFrom;
 
   nsEventStatus status; // ignored
   mGeckoChild->DispatchEvent(&event, status);
 }
 
-- (void)updateWindowDraggableState
-{
-  // Trigger update to the window server.
-  [[self window] setMovableByWindowBackground:NO];
-  [[self window] setMovableByWindowBackground:YES];
-}
-
-// aRect is in view coordinates relative to this NSView.
-- (CGRect)convertToFlippedWindowCoordinates:(NSRect)aRect
-{
-  // First, convert the rect to regular window coordinates...
-  NSRect inWindowCoords = [self convertRect:aRect toView:nil];
-  // ... and then flip it again because window coordinates have their origin
-  // in the bottom left corner, and we need it to be in the top left corner.
-  inWindowCoords.origin.y = [[self window] frame].size.height - NSMaxY(inWindowCoords);
-  return NSRectToCGRect(inWindowCoords);
-}
-
-static CGSRegionObj
-NewCGSRegionFromRegion(const LayoutDeviceIntRegion& aRegion,
-                       CGRect (^aRectConverter)(const LayoutDeviceIntRect&))
-{
-  nsTArray<CGRect> rects;
-  for (auto iter = aRegion.RectIter(); !iter.Done(); iter.Next()) {
-    rects.AppendElement(aRectConverter(iter.Get()));
-  }
-
-  CGSRegionObj region;
-  CGSNewRegionWithRectList(rects.Elements(), rects.Length(), &region);
-  return region;
-}
-
-// This function is called with forMove:YES to calculate the draggable region
-// of the window which will be submitted to the window server. Window dragging
-// is handled on the window server without calling back into our process, so it
-// also works while our app is unresponsive.
-- (CGSRegionObj)_regionForOpaqueDescendants:(NSRect)aRect forMove:(BOOL)aForMove
-{
-  if (!aForMove || !mGeckoChild) {
-    return [super _regionForOpaqueDescendants:aRect forMove:aForMove];
-  }
-
-  LayoutDeviceIntRect boundingRect = mGeckoChild->CocoaPointsToDevPixels(aRect);
-
-  LayoutDeviceIntRegion opaqueRegion;
-  opaqueRegion.Sub(boundingRect, mGeckoChild->GetDraggableRegion());
-
-  return NewCGSRegionFromRegion(opaqueRegion, ^(const LayoutDeviceIntRect& r) {
-    return [self convertToFlippedWindowCoordinates:mGeckoChild->DevPixelsToCocoaPoints(r)];
-  });
-}
-
-// Starting with 10.10, in addition to the traditional
-// -[NSView _regionForOpaqueDescendants:forMove:] method, there's a new form with
-// an additional forUnderTitlebar argument, which is sometimes called instead of
-// the old form. We need to override the new variant as well.
-- (CGSRegionObj)_regionForOpaqueDescendants:(NSRect)aRect
-                                    forMove:(BOOL)aForMove
-                           forUnderTitlebar:(BOOL)aForUnderTitlebar
-{
-  if (!aForMove || !mGeckoChild) {
-    return [super _regionForOpaqueDescendants:aRect
-                                      forMove:aForMove
-                             forUnderTitlebar:aForUnderTitlebar];
-  }
-
-  return [self _regionForOpaqueDescendants:aRect forMove:aForMove];
-}
-
 - (void)handleMouseMoved:(NSEvent*)theEvent
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
   if (!mGeckoChild)
     return;
   if (mTextInputHandler->OnHandleEvent(theEvent)) {
     return;
--- a/widget/cocoa/nsDeviceContextSpecX.mm
+++ b/widget/cocoa/nsDeviceContextSpecX.mm
@@ -152,17 +152,18 @@ NS_IMETHODIMP nsDeviceContextSpecX::GetS
 
     if (context) {
         // Initially, origin is at bottom-left corner of the paper.
         // Here, we translate it to top-left corner of the paper.
         CGContextTranslateCTM(context, 0, height);
         CGContextScaleCTM(context, 1.0, -1.0);
         newSurface = new gfxQuartzSurface(context, gfxSize(width, height));
     } else {
-        newSurface = new gfxQuartzSurface(gfxSize((int32_t)width, (int32_t)height), SurfaceFormat::A8R8G8B8_UINT32);
+        newSurface = new gfxQuartzSurface(gfxSize((int32_t)width, (int32_t)height),
+                                          mozilla::gfx::SurfaceFormat::A8R8G8B8_UINT32);
     }
 
     if (!newSurface)
         return NS_ERROR_FAILURE;
 
     *surface = newSurface;
     NS_ADDREF(*surface);
 
--- a/widget/cocoa/nsScreenCocoa.mm
+++ b/widget/cocoa/nsScreenCocoa.mm
@@ -39,64 +39,64 @@ nsScreenCocoa::GetId(uint32_t *outId)
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 NS_IMETHODIMP
 nsScreenCocoa::GetRect(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
 {
   NSRect frame = [mScreen frame];
 
-  LayoutDeviceIntRect r =
+  mozilla::LayoutDeviceIntRect r =
     nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, BackingScaleFactor());
 
   *outX = r.x;
   *outY = r.y;
   *outWidth = r.width;
   *outHeight = r.height;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsScreenCocoa::GetAvailRect(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
 {
   NSRect frame = [mScreen visibleFrame];
 
-  LayoutDeviceIntRect r =
+  mozilla::LayoutDeviceIntRect r =
     nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, BackingScaleFactor());
 
   *outX = r.x;
   *outY = r.y;
   *outWidth = r.width;
   *outHeight = r.height;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsScreenCocoa::GetRectDisplayPix(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
 {
   NSRect frame = [mScreen frame];
 
-  DesktopIntRect r = nsCocoaUtils::CocoaRectToGeckoRect(frame);
+  mozilla::DesktopIntRect r = nsCocoaUtils::CocoaRectToGeckoRect(frame);
 
   *outX = r.x;
   *outY = r.y;
   *outWidth = r.width;
   *outHeight = r.height;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsScreenCocoa::GetAvailRectDisplayPix(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
 {
   NSRect frame = [mScreen visibleFrame];
 
-  DesktopIntRect r = nsCocoaUtils::CocoaRectToGeckoRect(frame);
+  mozilla::DesktopIntRect r = nsCocoaUtils::CocoaRectToGeckoRect(frame);
 
   *outX = r.x;
   *outY = r.y;
   *outWidth = r.width;
   *outHeight = r.height;
 
   return NS_OK;
 }