diff options
author | andresantoso <andresantoso@chromium.org> | 2014-11-14 17:14:39 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-15 01:14:56 +0000 |
commit | f8f9fd1845d0e954f3d917bf64050ecd887b8811 (patch) | |
tree | ae41d4a3e43cefa3f1f597b2eef41c6edb0e9695 | |
parent | 96c8d8fa1d6d070e64697847f5f4291d2fe4d291 (diff) | |
download | chromium_src-f8f9fd1845d0e954f3d917bf64050ecd887b8811.zip chromium_src-f8f9fd1845d0e954f3d917bf64050ecd887b8811.tar.gz chromium_src-f8f9fd1845d0e954f3d917bf64050ecd887b8811.tar.bz2 |
MacViews: Fix inconsistencies with window modal dialog parent types.
On Aura, both gfx::NativeView and gfx::NativeWindow map to the same type
(aura::Window*).
On Mac, they map to different types (NSView* and NSWindow*) so they are not
interchangeable.
CreateBrowserModalDialogViews() is changed back to take a NativeWindow
parent because that is what the callers expect.
It was recently changed to NativeView in https://crrev.com/699553002.
Added platform_util::GetViewForWindow() to convert the parent to the
NativeView type that the Widget expects.
BUG=425229
Review URL: https://codereview.chromium.org/718913004
Cr-Commit-Position: refs/heads/master@{#304324}
10 files changed, 40 insertions, 24 deletions
diff --git a/athena/extensions/athena_constrained_window_views_client.cc b/athena/extensions/athena_constrained_window_views_client.cc index d56503f..1645639 100644 --- a/athena/extensions/athena_constrained_window_views_client.cc +++ b/athena/extensions/athena_constrained_window_views_client.cc @@ -19,7 +19,7 @@ namespace athena { namespace { -// Provides the host envrionment for web modal dialogs. See +// Provides the host environment for web modal dialogs. See // web_modal::WebContentsModalDialogHost, and ModalDialogHost for more // details. class ModalDialogHostImpl : public web_modal::WebContentsModalDialogHost, @@ -121,6 +121,9 @@ class AthenaConstrainedWindowViewsClient return ModalDialogHostImpl::Get(parent); return nullptr; } + gfx::NativeView GetDialogHostView(gfx::NativeWindow parent) override { + return parent; + } DISALLOW_COPY_AND_ASSIGN(AthenaConstrainedWindowViewsClient); }; diff --git a/chrome/browser/platform_util.h b/chrome/browser/platform_util.h index 916f3a3..3e93469 100644 --- a/chrome/browser/platform_util.h +++ b/chrome/browser/platform_util.h @@ -37,6 +37,11 @@ void OpenExternal(Profile* profile, const GURL& url); // Get the top level window for the native view. This can return NULL. gfx::NativeWindow GetTopLevel(gfx::NativeView view); +// Returns a NativeView handle for parenting dialogs off |window|. This can be +// used to position a dialog using a NativeWindow, when a NativeView (e.g. +// browser tab) isn't available. +gfx::NativeView GetViewForWindow(gfx::NativeWindow window); + // Get the direct parent of |view|, may return NULL. gfx::NativeView GetParent(gfx::NativeView view); diff --git a/chrome/browser/platform_util_aura.cc b/chrome/browser/platform_util_aura.cc index c56591f..db3a343 100644 --- a/chrome/browser/platform_util_aura.cc +++ b/chrome/browser/platform_util_aura.cc @@ -17,6 +17,11 @@ gfx::NativeWindow GetTopLevel(gfx::NativeView view) { return view->GetToplevelWindow(); } +gfx::NativeView GetViewForWindow(gfx::NativeWindow window) { + DCHECK(window); + return window; +} + gfx::NativeView GetParent(gfx::NativeView view) { return view->parent(); } diff --git a/chrome/browser/platform_util_mac.mm b/chrome/browser/platform_util_mac.mm index ef5fbe7..15622f1 100644 --- a/chrome/browser/platform_util_mac.mm +++ b/chrome/browser/platform_util_mac.mm @@ -149,6 +149,12 @@ gfx::NativeWindow GetTopLevel(gfx::NativeView view) { return [view window]; } +gfx::NativeView GetViewForWindow(gfx::NativeWindow window) { + DCHECK(window); + DCHECK([window contentView]); + return [window contentView]; +} + gfx::NativeView GetParent(gfx::NativeView view) { return nil; } diff --git a/chrome/browser/ui/views/chrome_constrained_window_views_client.cc b/chrome/browser/ui/views/chrome_constrained_window_views_client.cc index c286b3e4..7575b14 100644 --- a/chrome/browser/ui/views/chrome_constrained_window_views_client.cc +++ b/chrome/browser/ui/views/chrome_constrained_window_views_client.cc @@ -4,6 +4,7 @@ #include "chrome/browser/ui/views/chrome_constrained_window_views_client.h" +#include "chrome/browser/platform_util.h" #include "chrome/browser/ui/browser_finder.h" #include "components/web_modal/web_contents_modal_dialog_host.h" #include "extensions/browser/guest_view/guest_view_base.h" @@ -26,7 +27,7 @@ class ChromeConstrainedWindowViewsClient guest_view->embedder_web_contents() : initiator_web_contents; } web_modal::ModalDialogHost* GetModalDialogHost( - gfx::NativeView parent) override { + gfx::NativeWindow parent) override { // Get the browser dialog management and hosting components from |parent|. Browser* browser = chrome::FindBrowserWithWindow(parent); if (browser) { @@ -35,6 +36,9 @@ class ChromeConstrainedWindowViewsClient } return nullptr; } + gfx::NativeView GetDialogHostView(gfx::NativeWindow parent) override { + return platform_util::GetViewForWindow(parent); + } DISALLOW_COPY_AND_ASSIGN(ChromeConstrainedWindowViewsClient); }; diff --git a/chrome/browser/ui/views/chrome_constrained_window_views_client_mac.cc b/chrome/browser/ui/views/chrome_constrained_window_views_client_mac.cc deleted file mode 100644 index 142f45f..0000000 --- a/chrome/browser/ui/views/chrome_constrained_window_views_client_mac.cc +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/chrome_constrained_window_views_client.h" - -scoped_ptr<ConstrainedWindowViewsClient> -CreateChromeConstrainedWindowViewsClient() { - // Mac toolkit-views doesn't use constrained windows yet. - // TODO(tapted): Delete this file when it does. - return nullptr; -} diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi index 521aeed..9a6c69a 100644 --- a/chrome/chrome_browser_ui.gypi +++ b/chrome/chrome_browser_ui.gypi @@ -1928,8 +1928,6 @@ 'browser/ui/views/bookmarks/bookmark_sync_promo_view.cc', 'browser/ui/views/bookmarks/bookmark_sync_promo_view.h', 'browser/ui/views/certificate_viewer_win.cc', - 'browser/ui/views/chrome_constrained_window_views_client.cc', - 'browser/ui/views/chrome_constrained_window_views_client.h', 'browser/ui/views/chrome_javascript_native_dialog_factory_views.cc', 'browser/ui/views/chrome_views_delegate_chromeos.cc', 'browser/ui/views/chrome_web_dialog_view.cc', @@ -2243,7 +2241,8 @@ 'browser/ui/views/accessibility/accessibility_event_router_views.h', 'browser/ui/views/chrome_browser_main_extra_parts_views.cc', 'browser/ui/views/chrome_browser_main_extra_parts_views.h', - 'browser/ui/views/chrome_constrained_window_views_client_mac.cc', + 'browser/ui/views/chrome_constrained_window_views_client.cc', + 'browser/ui/views/chrome_constrained_window_views_client.h', 'browser/ui/views/chrome_views_delegate.cc', 'browser/ui/views/chrome_views_delegate.h', 'browser/ui/views/find_bar_host.cc', diff --git a/components/constrained_window/constrained_window_views.cc b/components/constrained_window/constrained_window_views.cc index dd4ada8..577ee03 100644 --- a/components/constrained_window/constrained_window_views.cc +++ b/components/constrained_window/constrained_window_views.cc @@ -154,19 +154,22 @@ views::Widget* CreateWebModalDialogViews(views::WidgetDelegate* dialog, // TODO(gbillock): Replace this with PopupManager calls. views::Widget* CreateBrowserModalDialogViews(views::DialogDelegate* dialog, - gfx::NativeView parent) { + gfx::NativeWindow parent) { DCHECK_NE(ui::MODAL_TYPE_CHILD, dialog->GetModalType()); DCHECK_NE(ui::MODAL_TYPE_NONE, dialog->GetModalType()); + DCHECK(constrained_window_views_client); + gfx::NativeView parent_view = + parent ? constrained_window_views_client->GetDialogHostView(parent) + : nullptr; views::Widget* widget = - views::DialogDelegate::CreateDialogWidget(dialog, NULL, parent); + views::DialogDelegate::CreateDialogWidget(dialog, NULL, parent_view); if (!dialog->UseNewStyleForThisDialog()) return widget; - DCHECK(constrained_window_views_client); ModalDialogHost* host = constrained_window_views_client-> GetModalDialogHost(parent); if (host) { - DCHECK_EQ(parent, host->GetHostView()); + DCHECK_EQ(parent_view, host->GetHostView()); ModalDialogHostObserver* dialog_host_observer = new WidgetModalDialogHostObserverViews( host, widget, kWidgetModalDialogHostObserverViewsKey); diff --git a/components/constrained_window/constrained_window_views.h b/components/constrained_window/constrained_window_views.h index ed4a828..e804676 100644 --- a/components/constrained_window/constrained_window_views.h +++ b/components/constrained_window/constrained_window_views.h @@ -56,7 +56,7 @@ views::Widget* CreateWebModalDialogViews(views::WidgetDelegate* dialog, // ui::MODAL_TYPE_SYSTEM or ui::MODAL_TYPE_WINDOW. This places the // dialog appropriately if |parent| is a valid browser window. views::Widget* CreateBrowserModalDialogViews(views::DialogDelegate* dialog, - gfx::NativeView parent); + gfx::NativeWindow parent); } // namespace constrained window diff --git a/components/constrained_window/constrained_window_views_client.h b/components/constrained_window/constrained_window_views_client.h index d0ec33c..c5b1860 100644 --- a/components/constrained_window/constrained_window_views_client.h +++ b/components/constrained_window/constrained_window_views_client.h @@ -26,9 +26,12 @@ class ConstrainedWindowViewsClient { virtual content::WebContents* GetEmbedderWebContents( content::WebContents* initiator_web_contents) = 0; - // Returns the modal window host for the |parent| native view. + // Returns the modal window host for the |parent| native window. virtual web_modal::ModalDialogHost* GetModalDialogHost( - gfx::NativeView parent) = 0; + gfx::NativeWindow parent) = 0; + + // Returns the native view in |window| appropriate for positioning dialogs. + virtual gfx::NativeView GetDialogHostView(gfx::NativeWindow window) = 0; }; } // namespace constrained window |