Bug 1527412 - Fix mParentView's type (it doesn't necessarily implement the mozView protocol) and tweak a few comments. r=spohl
authorMarkus Stange <mstange@themasta.com>
Wed, 13 Feb 2019 11:14:02 +0000
changeset 458919 fa484096ffd3
parent 458918 5b2aeaf2da17
child 458920 82aa9a03b71d
push id35551
push usershindli@mozilla.com
push dateWed, 13 Feb 2019 21:34:09 +0000
treeherdermozilla-central@08f794a4928e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersspohl
bugs1527412
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1527412 - Fix mParentView's type (it doesn't necessarily implement the mozView protocol) and tweak a few comments. r=spohl Differential Revision: https://phabricator.services.mozilla.com/D19554
widget/cocoa/mozView.h
widget/cocoa/nsChildView.h
widget/cocoa/nsChildView.mm
--- a/widget/cocoa/mozView.h
+++ b/widget/cocoa/mozView.h
@@ -11,20 +11,23 @@
 class nsIWidget;
 
 namespace mozilla {
 namespace widget {
 class TextInputHandler;
 }  // namespace widget
 }  // namespace mozilla
 
-// A protocol listing all the methods that an object which wants
-// to live in gecko's widget hierarchy must implement. |nsChildView|
-// makes assumptions that any NSView with which it comes in contact will
-// implement this protocol.
+// A protocol with some of the methods that ChildView implements. In the distant
+// past, this protocol was used by embedders: They would create their own NSView
+// subclass, implement mozView on it, and then embed a Gecko ChildView by adding
+// it as a subview of this view. This scenario no longer exists.
+// Now this protocol is mostly just used by TextInputHandler and mozAccessible
+// in order to communicate with ChildView without seeing the entire ChildView
+// interface definition.
 @protocol mozView
 
 // aHandler is Gecko's default text input handler:  It implements the
 // NSTextInput protocol to handle key events.  Don't make aHandler a
 // strong reference -- that causes a memory leak.
 - (void)installTextInputHandler:(mozilla::widget::TextInputHandler*)aHandler;
 - (void)uninstallTextInputHandler;
 
--- a/widget/cocoa/nsChildView.h
+++ b/widget/cocoa/nsChildView.h
@@ -566,17 +566,17 @@ class nsChildView final : public nsBaseW
   void TrackScrollEventAsSwipe(const mozilla::PanGestureInput& aSwipeStartEvent,
                                uint32_t aAllowedDirections);
 
  protected:
   NSView<mozView>* mView;  // my parallel cocoa view (ChildView or NativeScrollbarView), [STRONG]
   RefPtr<mozilla::widget::TextInputHandler> mTextInputHandler;
   InputContext mInputContext;
 
-  NSView<mozView>* mParentView;
+  NSView* mParentView;
   nsIWidget* mParentWidget;
 
 #ifdef ACCESSIBILITY
   // weak ref to this childview's associated mozAccessible for speed reasons
   // (we get queried for it *a lot* but don't want to own it)
   nsWeakPtr mAccessible;
 #endif
 
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -312,17 +312,17 @@ struct SwipeEventQueue {
 
 }  // namespace mozilla
 
 #pragma mark -
 
 nsChildView::nsChildView()
     : nsBaseWidget(),
       mView(nullptr),
-      mParentView(nullptr),
+      mParentView(nil),
       mParentWidget(nullptr),
       mViewTearDownLock("ChildViewTearDown"),
       mEffectsLock("WidgetEffects"),
       mShowsResizeIndicator(false),
       mHasRoundedBottomCorners(false),
       mDevPixelCornerRadius{0},
       mIsCoveringTitlebar(false),
       mIsFullscreen(false),
@@ -395,30 +395,29 @@ nsresult nsChildView::Create(nsIWidget* 
 
   mBounds = aRect;
 
   // Ensure that the toolkit is created.
   nsToolkit::GetToolkit();
 
   BaseCreate(aParent, aInitData);
 
-  // inherit things from the parent view and create our parallel
-  // NSView in the Cocoa display system
   mParentView = nil;
   if (aParent) {
-    // inherit the top-level window. NS_NATIVE_WIDGET is always a NSView
-    // regardless of if we're asking a window or a view (for compatibility
-    // with windows).
-    mParentView = (NSView<mozView>*)aParent->GetNativeData(NS_NATIVE_WIDGET);
+    // This is the popup window case. aParent is the nsCocoaWindow for the
+    // popup window, and mParentView will be its content view.
+    mParentView = (NSView*)aParent->GetNativeData(NS_NATIVE_WIDGET);
     mParentWidget = aParent;
   } else {
-    // This is the normal case. When we're the root widget of the view hiararchy,
+    // This is the top-level window case.
     // aNativeParent will be the contentView of our window, since that's what
     // nsCocoaWindow returns when asked for an NS_NATIVE_VIEW.
-    mParentView = reinterpret_cast<NSView<mozView>*>(aNativeParent);
+    // We do not have a direct "parent widget" association with the top level
+    // window's nsCocoaWindow object.
+    mParentView = reinterpret_cast<NSView*>(aNativeParent);
   }
 
   // create our parallel NSView and hook it up to our parent. Recall
   // that NS_NATIVE_WIDGET is the NSView.
   CGFloat scaleFactor = nsCocoaUtils::GetBackingScaleFactor(mParentView);
   NSRect r = nsCocoaUtils::DevPixelsToCocoaPoints(mBounds, scaleFactor);
   mView = [(NSView<mozView>*)CreateCocoaView(r) retain];
   if (!mView) {