Skip to content

Commit

Permalink
Use DialogDelegate for kAnchoredDialogKey
Browse files Browse the repository at this point in the history
Prerequisite for focus traversal into anchored DialogDelegates. There
are currently none of those as anchor functionality is in
BubbleDialogDelegate.

Bug: 1144829
Change-Id: I6dcfd11cdae4f74b79190ec6461437a05200ddc3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2514664
Commit-Queue: Peter Boström <pbos@chromium.org>
Reviewed-by: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823792}
  • Loading branch information
pbos authored and Commit Bot committed Nov 3, 2020
1 parent bf11011 commit 4d70001
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion chrome/browser/ui/views/accessibility/caption_bubble.cc
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ void CaptionBubble::AddedToWidget() {
anchor_widget()->GetFocusTraversable());
GetWidget()->SetFocusTraversableParentView(GetAnchorView());
GetAnchorView()->SetProperty(views::kAnchoredDialogKey,
static_cast<BubbleDialogDelegate*>(this));
static_cast<DialogDelegate*>(this));
}

void CaptionBubble::CloseButtonPressed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class ExtensionsMenuViewBrowserTest : public ExtensionsToolbarBrowserTest {
if (ui_test_name_ == "InstallDialog") {
ExtensionsToolbarContainer* const container =
GetExtensionsToolbarContainer();
views::BubbleDialogDelegate* const install_bubble =
views::DialogDelegate* const install_bubble =
container->GetViewForId(extensions()[0]->id())
->GetProperty(views::kAnchoredDialogKey);
ASSERT_TRUE(install_bubble);
Expand All @@ -165,7 +165,7 @@ class ExtensionsMenuViewBrowserTest : public ExtensionsToolbarBrowserTest {
ExtensionsToolbarContainer* const container =
GetExtensionsToolbarContainer();
// Accept or cancel the dialog.
views::BubbleDialogDelegate* const uninstall_bubble =
views::DialogDelegate* const uninstall_bubble =
container->GetViewForId(extensions()[0]->id())
->GetProperty(views::kAnchoredDialogKey);
ASSERT_TRUE(uninstall_bubble);
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/views/frame/browser_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,7 @@ bool BrowserView::ActivateFirstInactiveBubbleForAccessibility() {
// general solution should be desirable to find any bubbles anchored in the
// views hierarchy.
if (toolbar_ && toolbar_->app_menu_button()) {
views::BubbleDialogDelegate* bubble =
views::DialogDelegate* bubble =
toolbar_->app_menu_button()->GetProperty(views::kAnchoredDialogKey);
if (!bubble && GetLocationBarView())
bubble = GetLocationBarView()->GetProperty(views::kAnchoredDialogKey);
Expand Down
3 changes: 2 additions & 1 deletion ui/views/bubble/bubble_dialog_delegate_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,8 @@ void BubbleDialogDelegate::SetAnchorView(View* anchor_view) {
auto* old_anchored_dialog = anchor_view->GetProperty(kAnchoredDialogKey);
if (old_anchored_dialog && old_anchored_dialog != this)
DLOG(WARNING) << "|anchor_view| has already anchored a focusable widget.";
anchor_view->SetProperty(kAnchoredDialogKey, this);
anchor_view->SetProperty(kAnchoredDialogKey,
static_cast<DialogDelegate*>(this));
}
}

Expand Down
10 changes: 4 additions & 6 deletions ui/views/focus/focus_search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

#include "base/logging.h"
#include "build/build_config.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
#include "ui/views/focus/focus_manager.h"
#include "ui/views/view.h"
#include "ui/views/view_class_properties.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_delegate.h"

namespace views {

Expand Down Expand Up @@ -203,8 +203,7 @@ View* FocusSearch::FindNextFocusableViewImpl(
// Check to see if we should navigate into a dialog anchored at this view.
if (can_go_into_anchored_dialog ==
AnchoredDialogPolicy::kCanGoIntoAnchoredDialog) {
BubbleDialogDelegate* bubble =
starting_view->GetProperty(kAnchoredDialogKey);
DialogDelegate* bubble = starting_view->GetProperty(kAnchoredDialogKey);
if (bubble) {
*focus_traversable = bubble->GetWidget()->GetFocusTraversable();
*focus_traversable_view = starting_view;
Expand All @@ -230,7 +229,7 @@ View* FocusSearch::FindNextFocusableViewImpl(
while (parent && parent != root_) {
if (can_go_into_anchored_dialog ==
AnchoredDialogPolicy::kCanGoIntoAnchoredDialog) {
BubbleDialogDelegate* bubble = parent->GetProperty(kAnchoredDialogKey);
DialogDelegate* bubble = parent->GetProperty(kAnchoredDialogKey);
if (bubble) {
*focus_traversable = bubble->GetWidget()->GetFocusTraversable();
*focus_traversable_view = starting_view;
Expand Down Expand Up @@ -301,8 +300,7 @@ View* FocusSearch::FindPreviousFocusableViewImpl(
// Check to see if we should navigate into a dialog anchored at this view.
if (can_go_into_anchored_dialog ==
AnchoredDialogPolicy::kCanGoIntoAnchoredDialog) {
BubbleDialogDelegate* bubble =
starting_view->GetProperty(kAnchoredDialogKey);
DialogDelegate* bubble = starting_view->GetProperty(kAnchoredDialogKey);
if (bubble) {
*focus_traversable = bubble->GetWidget()->GetFocusTraversable();
*focus_traversable_view = starting_view;
Expand Down
5 changes: 2 additions & 3 deletions ui/views/view_class_properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ DEFINE_EXPORTED_UI_CLASS_PROPERTY_TYPE(VIEWS_EXPORT, int)

DEFINE_EXPORTED_UI_CLASS_PROPERTY_TYPE(VIEWS_EXPORT, gfx::Insets*)

DEFINE_EXPORTED_UI_CLASS_PROPERTY_TYPE(VIEWS_EXPORT,
views::BubbleDialogDelegate*)
DEFINE_EXPORTED_UI_CLASS_PROPERTY_TYPE(VIEWS_EXPORT, views::DialogDelegate*)

DEFINE_EXPORTED_UI_CLASS_PROPERTY_TYPE(VIEWS_EXPORT,
views::HighlightPathGenerator*)
Expand All @@ -32,7 +31,7 @@ namespace views {
DEFINE_UI_CLASS_PROPERTY_KEY(int, kHitTestComponentKey, HTNOWHERE)
DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Insets, kMarginsKey, nullptr)
DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Insets, kInternalPaddingKey, nullptr)
DEFINE_UI_CLASS_PROPERTY_KEY(views::BubbleDialogDelegate*,
DEFINE_UI_CLASS_PROPERTY_KEY(views::DialogDelegate*,
kAnchoredDialogKey,
nullptr)
DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(views::HighlightPathGenerator,
Expand Down
7 changes: 3 additions & 4 deletions ui/views/view_class_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Insets;

namespace views {

class BubbleDialogDelegate;
class DialogDelegate;
class FlexSpecification;
class HighlightPathGenerator;

Expand All @@ -42,7 +42,7 @@ VIEWS_EXPORT extern const ui::ClassProperty<gfx::Insets*>* const

// A property to store the bubble dialog anchored to this view, to
// enable the bubble's contents to be included in the focus order.
VIEWS_EXPORT extern const ui::ClassProperty<BubbleDialogDelegate*>* const
VIEWS_EXPORT extern const ui::ClassProperty<DialogDelegate*>* const
kAnchoredDialogKey;

// A property to store a highlight-path generator. This generator is used to
Expand All @@ -66,8 +66,7 @@ VIEWS_EXPORT extern const ui::ClassProperty<LayoutAlignment*>* const
// template instance before its specialization is declared in a
// translation unit is a C++ error.
DECLARE_EXPORTED_UI_CLASS_PROPERTY_TYPE(VIEWS_EXPORT, gfx::Insets*)
DECLARE_EXPORTED_UI_CLASS_PROPERTY_TYPE(VIEWS_EXPORT,
views::BubbleDialogDelegate*)
DECLARE_EXPORTED_UI_CLASS_PROPERTY_TYPE(VIEWS_EXPORT, views::DialogDelegate*)
DECLARE_EXPORTED_UI_CLASS_PROPERTY_TYPE(VIEWS_EXPORT,
views::HighlightPathGenerator*)
DECLARE_EXPORTED_UI_CLASS_PROPERTY_TYPE(VIEWS_EXPORT, views::FlexSpecification*)
Expand Down

0 comments on commit 4d70001

Please sign in to comment.