Commit 01b39191 authored by spqchan's avatar spqchan Committed by Commit Bot

[MacViews] Wire up AutofillPopupView

Show toolkit-views AutofillPopupView with --secondary-ui-md.

Removed AutofillPopupBaseView FocusManager accelerator code.
The code is no longer necessary since it was added for a now
obsolete rAc dialog. The autofill popup will get dismissed by
the web contents, which listens for the accelerators.

Bug: 728182
Change-Id: I9f7816fe41279a397f5066d28d88099d50ef033e
Reviewed-on: https://chromium-review.googlesource.com/889983
Commit-Queue: Sarah Chan <spqchan@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#534527}
parent 041cd10c
...@@ -66,8 +66,8 @@ split_static_library("ui") { ...@@ -66,8 +66,8 @@ split_static_library("ui") {
"cocoa/autofill/autofill_dialog_constants.h", "cocoa/autofill/autofill_dialog_constants.h",
"cocoa/autofill/autofill_popup_base_view_cocoa.h", "cocoa/autofill/autofill_popup_base_view_cocoa.h",
"cocoa/autofill/autofill_popup_base_view_cocoa.mm", "cocoa/autofill/autofill_popup_base_view_cocoa.mm",
"cocoa/autofill/autofill_popup_view_bridge.h", "cocoa/autofill/autofill_popup_view_bridge_views.h",
"cocoa/autofill/autofill_popup_view_bridge.mm", "cocoa/autofill/autofill_popup_view_bridge_views.mm",
"cocoa/autofill/autofill_popup_view_cocoa.h", "cocoa/autofill/autofill_popup_view_cocoa.h",
"cocoa/autofill/autofill_popup_view_cocoa.mm", "cocoa/autofill/autofill_popup_view_cocoa.mm",
"cocoa/autofill/autofill_tooltip_controller.h", "cocoa/autofill/autofill_tooltip_controller.h",
...@@ -2737,6 +2737,12 @@ split_static_library("ui") { ...@@ -2737,6 +2737,12 @@ split_static_library("ui") {
"views/apps/app_info_dialog/app_info_summary_panel.h", "views/apps/app_info_dialog/app_info_summary_panel.h",
"views/apps/chrome_native_app_window_views.cc", "views/apps/chrome_native_app_window_views.cc",
"views/apps/chrome_native_app_window_views.h", "views/apps/chrome_native_app_window_views.h",
"views/autofill/autofill_popup_base_view.cc",
"views/autofill/autofill_popup_base_view.h",
"views/autofill/autofill_popup_view_native_views.cc",
"views/autofill/autofill_popup_view_native_views.h",
"views/autofill/autofill_popup_view_views.cc",
"views/autofill/autofill_popup_view_views.h",
"views/autofill/card_unmask_prompt_views.cc", "views/autofill/card_unmask_prompt_views.cc",
"views/autofill/card_unmask_prompt_views.h", "views/autofill/card_unmask_prompt_views.h",
"views/autofill/save_card_bubble_views.cc", "views/autofill/save_card_bubble_views.cc",
...@@ -2976,12 +2982,6 @@ split_static_library("ui") { ...@@ -2976,12 +2982,6 @@ split_static_library("ui") {
"javascript_dialogs/javascript_dialog.cc", "javascript_dialogs/javascript_dialog.cc",
"views/accessibility/invert_bubble_view.cc", "views/accessibility/invert_bubble_view.cc",
"views/accessibility/invert_bubble_view.h", "views/accessibility/invert_bubble_view.h",
"views/autofill/autofill_popup_base_view.cc",
"views/autofill/autofill_popup_base_view.h",
"views/autofill/autofill_popup_view_native_views.cc",
"views/autofill/autofill_popup_view_native_views.h",
"views/autofill/autofill_popup_view_views.cc",
"views/autofill/autofill_popup_view_views.h",
"views/autofill/password_generation_popup_view_views.cc", "views/autofill/password_generation_popup_view_views.cc",
"views/autofill/password_generation_popup_view_views.h", "views/autofill/password_generation_popup_view_views.h",
"views/autofill/save_card_icon_view.cc", "views/autofill/save_card_icon_view.cc",
......
...@@ -4,13 +4,15 @@ ...@@ -4,13 +4,15 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#include "chrome/browser/ui/cocoa/autofill/autofill_popup_view_bridge.h" #include "chrome/browser/ui/cocoa/autofill/autofill_popup_view_bridge_views.h"
#include "base/logging.h" #include "base/logging.h"
#include "chrome/browser/ui/autofill/autofill_popup_controller.h" #include "chrome/browser/ui/autofill/autofill_popup_controller.h"
#include "chrome/browser/ui/autofill/autofill_popup_layout_model.h" #include "chrome/browser/ui/autofill/autofill_popup_layout_model.h"
#include "chrome/browser/ui/autofill/autofill_popup_view_delegate.h" #include "chrome/browser/ui/autofill/autofill_popup_view_delegate.h"
#import "chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.h" #import "chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.h"
#include "chrome/browser/ui/cocoa/browser_dialogs_views_mac.h"
#include "chrome/browser/ui/views/autofill/autofill_popup_view_views.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
namespace autofill { namespace autofill {
...@@ -63,6 +65,9 @@ void AutofillPopupViewBridge::OnSuggestionsChanged() { ...@@ -63,6 +65,9 @@ void AutofillPopupViewBridge::OnSuggestionsChanged() {
AutofillPopupView* AutofillPopupView::Create( AutofillPopupView* AutofillPopupView::Create(
AutofillPopupController* controller) { AutofillPopupController* controller) {
if (chrome::ShowAllDialogsWithViewsToolkit())
return AutofillPopupViewViews::Create(controller);
return new AutofillPopupViewBridge(controller); return new AutofillPopupViewBridge(controller);
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "chrome/app/vector_icons/vector_icons.h" #include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/ui/autofill/autofill_popup_controller.h" #include "chrome/browser/ui/autofill/autofill_popup_controller.h"
#include "chrome/browser/ui/autofill/autofill_popup_layout_model.h" #include "chrome/browser/ui/autofill/autofill_popup_layout_model.h"
#include "chrome/browser/ui/cocoa/autofill/autofill_popup_view_bridge.h" #include "chrome/browser/ui/cocoa/autofill/autofill_popup_view_bridge_views.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h" #import "chrome/browser/ui/cocoa/browser_window_controller.h"
#import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h"
#import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
......
...@@ -9,6 +9,10 @@ ...@@ -9,6 +9,10 @@
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "ui/base/ui_features.h"
#include "ui/native_theme/native_theme.h" #include "ui/native_theme/native_theme.h"
#include "ui/views/border.h" #include "ui/views/border.h"
#include "ui/views/controls/scroll_view.h" #include "ui/views/controls/scroll_view.h"
...@@ -48,24 +52,20 @@ AutofillPopupBaseView::~AutofillPopupBaseView() { ...@@ -48,24 +52,20 @@ AutofillPopupBaseView::~AutofillPopupBaseView() {
void AutofillPopupBaseView::DoShow() { void AutofillPopupBaseView::DoShow() {
const bool initialize_widget = !GetWidget(); const bool initialize_widget = !GetWidget();
if (initialize_widget) { if (initialize_widget) {
#if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER)
// Without this, the popup will not dismiss if the window is moved.
// TODO(spqchan): Find a way to dismiss the popup when the window is moved.
// See https://crbug.com/808270.
parent_widget_->AddObserver(this); parent_widget_->AddObserver(this);
views::FocusManager* focus_manager = parent_widget_->GetFocusManager(); #endif
focus_manager->RegisterAccelerator(
ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE),
ui::AcceleratorManager::kNormalPriority,
this);
focus_manager->RegisterAccelerator(
ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE),
ui::AcceleratorManager::kNormalPriority,
this);
// The widget is destroyed by the corresponding NativeWidget, so we use // The widget is destroyed by the corresponding NativeWidget, so we use
// a weak pointer to hold the reference and don't have to worry about // a weak pointer to hold the reference and don't have to worry about
// deletion. // deletion.
views::Widget* widget = new views::Widget; views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
params.delegate = this; params.delegate = this;
params.parent = parent_widget_->GetNativeView(); params.parent = parent_widget_ ? parent_widget_->GetNativeView()
: delegate_->container_view();
widget->Init(params); widget->Init(params);
scroll_view_ = new views::ScrollView; scroll_view_ = new views::ScrollView;
...@@ -118,8 +118,9 @@ void AutofillPopupBaseView::OnWidgetBoundsChanged(views::Widget* widget, ...@@ -118,8 +118,9 @@ void AutofillPopupBaseView::OnWidgetBoundsChanged(views::Widget* widget,
} }
void AutofillPopupBaseView::RemoveObserver() { void AutofillPopupBaseView::RemoveObserver() {
parent_widget_->GetFocusManager()->UnregisterAccelerators(this); #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER)
parent_widget_->RemoveObserver(this); parent_widget_->RemoveObserver(this);
#endif
views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this); views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this);
} }
...@@ -136,9 +137,22 @@ void AutofillPopupBaseView::DoUpdateBoundsAndRedrawPopup() { ...@@ -136,9 +137,22 @@ void AutofillPopupBaseView::DoUpdateBoundsAndRedrawPopup() {
// Compute the space available for the popup. It's the space between its top // Compute the space available for the popup. It's the space between its top
// and the bottom of its parent view, minus some margin space. // and the bottom of its parent view, minus some margin space.
int available_vertical_space = gfx::Rect clipping_bounds;
parent_widget_->GetClientAreaBoundsInScreen().height() - #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER)
(bounds.y() - parent_widget_->GetClientAreaBoundsInScreen().y()) - clipping_bounds = parent_widget_->GetClientAreaBoundsInScreen();
#else
gfx::NativeWindow window =
platform_util::GetTopLevel(delegate_->container_view());
Browser* browser = chrome::FindBrowserWithWindow(window);
DCHECK(browser);
// This is not the same as "GetClientAreaBoundsInScreen()", but it gives us
// the lower bounds the popup will have to clip to on the screen.
clipping_bounds = browser->window()->GetBounds();
#endif
int available_vertical_space = clipping_bounds.height() -
(bounds.y() - clipping_bounds.y()) -
kPopupBottomMargin; kPopupBottomMargin;
if (available_vertical_space < bounds.height()) { if (available_vertical_space < bounds.height()) {
...@@ -244,22 +258,6 @@ void AutofillPopupBaseView::OnGestureEvent(ui::GestureEvent* event) { ...@@ -244,22 +258,6 @@ void AutofillPopupBaseView::OnGestureEvent(ui::GestureEvent* event) {
event->SetHandled(); event->SetHandled();
} }
bool AutofillPopupBaseView::AcceleratorPressed(
const ui::Accelerator& accelerator) {
DCHECK_EQ(accelerator.modifiers(), ui::EF_NONE);
if (accelerator.key_code() == ui::VKEY_ESCAPE) {
HideController();
return true;
}
if (accelerator.key_code() == ui::VKEY_RETURN)
return delegate_->AcceptSelectedLine();
NOTREACHED();
return false;
}
void AutofillPopupBaseView::SetSelection(const gfx::Point& point) { void AutofillPopupBaseView::SetSelection(const gfx::Point& point) {
if (delegate_) if (delegate_)
delegate_->SetSelectionAtPoint(point); delegate_->SetSelectionAtPoint(point);
......
...@@ -54,7 +54,6 @@ class AutofillPopupBaseView : public views::WidgetDelegateView, ...@@ -54,7 +54,6 @@ class AutofillPopupBaseView : public views::WidgetDelegateView,
bool OnMousePressed(const ui::MouseEvent& event) override; bool OnMousePressed(const ui::MouseEvent& event) override;
void OnMouseReleased(const ui::MouseEvent& event) override; void OnMouseReleased(const ui::MouseEvent& event) override;
void OnGestureEvent(ui::GestureEvent* event) override; void OnGestureEvent(ui::GestureEvent* event) override;
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
// views::WidgetFocusChangeListener implementation. // views::WidgetFocusChangeListener implementation.
void OnNativeFocusChanged(gfx::NativeView focused_now) override; void OnNativeFocusChanged(gfx::NativeView focused_now) override;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/optional.h" #include "base/optional.h"
#include "build/build_config.h"
#include "chrome/browser/ui/autofill/autofill_popup_controller.h" #include "chrome/browser/ui/autofill/autofill_popup_controller.h"
#include "chrome/browser/ui/autofill/autofill_popup_layout_model.h" #include "chrome/browser/ui/autofill/autofill_popup_layout_model.h"
#include "chrome/browser/ui/views/autofill/autofill_popup_view_native_views.h" #include "chrome/browser/ui/views/autofill/autofill_popup_view_native_views.h"
...@@ -15,6 +16,7 @@ ...@@ -15,6 +16,7 @@
#include "components/autofill/core/browser/suggestion.h" #include "components/autofill/core/browser/suggestion.h"
#include "ui/accessibility/ax_node_data.h" #include "ui/accessibility/ax_node_data.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/ui_features.h"
#include "ui/events/keycodes/keyboard_codes.h" #include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/point.h"
...@@ -256,16 +258,18 @@ void AutofillPopupViewViews::CreateChildViews() { ...@@ -256,16 +258,18 @@ void AutofillPopupViewViews::CreateChildViews() {
} }
} }
AutofillPopupView* AutofillPopupView::Create( AutofillPopupView* AutofillPopupViewViews::Create(
AutofillPopupController* controller) { AutofillPopupController* controller) {
views::Widget* observing_widget = views::Widget* observing_widget =
views::Widget::GetTopLevelWidgetForNativeView( views::Widget::GetTopLevelWidgetForNativeView(
controller->container_view()); controller->container_view());
#if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER)
// If the top level widget can't be found, cancel the popup since we can't // If the top level widget can't be found, cancel the popup since we can't
// fully set it up. // fully set it up.
if (!observing_widget) if (!observing_widget)
return NULL; return NULL;
#endif
if (base::FeatureList::IsEnabled(autofill::kAutofillExpandedPopupViews)) if (base::FeatureList::IsEnabled(autofill::kAutofillExpandedPopupViews))
return new AutofillPopupViewNativeViews(controller, observing_widget); return new AutofillPopupViewNativeViews(controller, observing_widget);
...@@ -273,4 +277,11 @@ AutofillPopupView* AutofillPopupView::Create( ...@@ -273,4 +277,11 @@ AutofillPopupView* AutofillPopupView::Create(
return new AutofillPopupViewViews(controller, observing_widget); return new AutofillPopupViewViews(controller, observing_widget);
} }
#if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER)
AutofillPopupView* AutofillPopupView::Create(
AutofillPopupController* controller) {
return AutofillPopupViewViews::Create(controller);
}
#endif
} // namespace autofill } // namespace autofill
...@@ -25,6 +25,8 @@ class AutofillPopupViewViews : public AutofillPopupBaseView, ...@@ -25,6 +25,8 @@ class AutofillPopupViewViews : public AutofillPopupBaseView,
views::Widget* parent_widget); views::Widget* parent_widget);
~AutofillPopupViewViews() override; ~AutofillPopupViewViews() override;
static AutofillPopupView* Create(AutofillPopupController* controller);
private: private:
FRIEND_TEST_ALL_PREFIXES(AutofillPopupViewViewsTest, OnSelectedRowChanged); FRIEND_TEST_ALL_PREFIXES(AutofillPopupViewViewsTest, OnSelectedRowChanged);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment